Class: Ruco::FileStore

Inherits:
Object show all
Defined in:
lib/ruco/file_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(folder, options) ⇒ FileStore

Returns a new instance of FileStore.



6
7
8
9
# File 'lib/ruco/file_store.rb', line 6

def initialize(folder, options)
  @folder = folder
  @options = options
end

Instance Method Details

#get(key) ⇒ Object



17
18
19
20
# File 'lib/ruco/file_store.rb', line 17

def get(key)
  file = file(key)
  deserialize File.binary_read(file) if File.exist?(file)
end

#set(key, value) ⇒ Object



11
12
13
14
15
# File 'lib/ruco/file_store.rb', line 11

def set(key, value)
  FileUtils.mkdir_p @folder unless File.exist? @folder
  File.write(file(key), serialize(value))
  cleanup
end