Class: Jetmeter::Config::FileCacheStore

Inherits:
Object
  • Object
show all
Defined in:
lib/jetmeter/config/file_cache_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ FileCacheStore

Returns a new instance of FileCacheStore.

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
# File 'lib/jetmeter/config/file_cache_store.rb', line 4

def initialize(root_path)
  raise ArgumentError unless File.exist?(root_path)
  raise ArgumentError unless File.directory?(root_path)
  raise ArgumentError unless File.writable?(root_path)

  @root_path = root_path
end

Instance Method Details

#delete(key) ⇒ Object



22
23
24
25
26
# File 'lib/jetmeter/config/file_cache_store.rb', line 22

def delete(key)
  if File.exist?(path(key))
    File.delete(path(key))
  end
end

#read(key) ⇒ Object



12
13
14
15
16
# File 'lib/jetmeter/config/file_cache_store.rb', line 12

def read(key)
  if readable?(key)
    File.open(path(key)) { |f| Marshal.load(f) }
  end
end

#write(key, value) ⇒ Object



18
19
20
# File 'lib/jetmeter/config/file_cache_store.rb', line 18

def write(key, value)
  File.open(path(key), 'wb') { |f| Marshal.dump(value, f) }
end