Class: Profiler::Storage::BlobStore

Inherits:
Object
  • Object
show all
Defined in:
lib/profiler/storage/blob_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ BlobStore

Returns a new instance of BlobStore.



9
10
11
12
# File 'lib/profiler/storage/blob_store.rb', line 9

def initialize(path)
  @path = path
  FileUtils.mkdir_p(@path)
end

Instance Method Details

#delete(token) ⇒ Object



30
31
32
33
# File 'lib/profiler/storage/blob_store.rb', line 30

def delete(token)
  dir = token_dir(token)
  FileUtils.rm_rf(dir) if File.directory?(dir)
end

#exists?(token, collector_name) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/profiler/storage/blob_store.rb', line 35

def exists?(token, collector_name)
  File.exist?(File.join(token_dir(token), "#{collector_name}.json"))
end

#read(token, collector_name) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/profiler/storage/blob_store.rb', line 20

def read(token, collector_name)
  file = File.join(token_dir(token), "#{collector_name}.json")
  return nil unless File.exist?(file)

  JSON.parse(File.read(file))
rescue => e
  warn "BlobStore: failed to read #{token}/#{collector_name}: #{e.message}"
  nil
end

#write(token, collector_name, data) ⇒ Object



14
15
16
17
18
# File 'lib/profiler/storage/blob_store.rb', line 14

def write(token, collector_name, data)
  dir = token_dir(token)
  FileUtils.mkdir_p(dir)
  File.write(File.join(dir, "#{collector_name}.json"), JSON.generate(data))
end