Class: Moneta::Adapters::Xattr

Inherits:
Object
  • Object
show all
Includes:
Defaults
Defined in:
lib/moneta/adapters/xattr.rb

Instance Method Summary collapse

Methods included from Defaults

#[]=, #fetch

Constructor Details

#initialize(options = {}) ⇒ Xattr

Returns a new instance of Xattr.



14
15
16
17
18
19
# File 'lib/moneta/adapters/xattr.rb', line 14

def initialize(options = {})
  file = options[:file]
  @hash = ::Xattr.new(file)
  FileUtils.mkdir_p(::File.dirname(file))
  FileUtils.touch(file)
end

Instance Method Details

#[](key) ⇒ Object



25
26
27
28
29
# File 'lib/moneta/adapters/xattr.rb', line 25

def [](key)
  string_key = key_for(key)
  return nil unless key?(string_key)
  Marshal.load(@hash.get(string_key))
end

#clearObject



42
43
44
45
46
# File 'lib/moneta/adapters/xattr.rb', line 42

def clear(*)
  @hash.list.each do |item|
    @hash.remove(item)
  end
end

#delete(key) ⇒ Object



35
36
37
38
39
40
# File 'lib/moneta/adapters/xattr.rb', line 35

def delete(key, *)
  return nil unless key?(key)
  value = self[key]
  @hash.remove(key_for(key))
  value
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/moneta/adapters/xattr.rb', line 21

def key?(key, *)
  @hash.list.include?(key_for(key))
end

#store(key, value) ⇒ Object



31
32
33
# File 'lib/moneta/adapters/xattr.rb', line 31

def store(key, value, *)
  @hash.set(key_for(key), Marshal.dump(value))
end