Class: Moneta::BasicFile

Inherits:
Object show all
Defined in:
lib/chef/monkey_patches/moneta.rb

Instance Method Summary collapse

Instance Method Details

#raw_get(key) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/chef/monkey_patches/moneta.rb', line 40

def raw_get(key)
  if ::File.respond_to?(:binread)
    data = ::File.binread(path(key))
  else
    data = ::File.open(path(key),"rb") { |f| f.read }
  end
  Marshal.load(data)
end

#store(key, value, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/chef/monkey_patches/moneta.rb', line 24

def store(key, value, options = {})
  ensure_directory_created(::File.dirname(path(key)))
  ::File.open(path(key), "wb") do |file|
    if @expires
      data = {:value => value}
      if options[:expires_in]
        data[:expires_at] = Time.now + options[:expires_in]
      end
      contents = Marshal.dump(data)
    else
      contents = Marshal.dump(value)
    end
    file.puts(contents)
  end
end