Class: Trocla::Stores::Moneta

Inherits:
Trocla::Store show all
Defined in:
lib/trocla/stores/moneta.rb

Overview

the default moneta based store

Instance Attribute Summary collapse

Attributes inherited from Trocla::Store

#store_config, #trocla

Instance Method Summary collapse

Methods inherited from Trocla::Store

#delete, #set

Constructor Details

#initialize(config, trocla) ⇒ Moneta

Returns a new instance of Moneta.



5
6
7
8
9
10
11
12
13
# File 'lib/trocla/stores/moneta.rb', line 5

def initialize(config, trocla)
  super(config, trocla)
  require 'moneta'
  # load expire support by default
  adapter_options = {
    :expires => true
  }.merge(store_config['adapter_options'] || {})
  @moneta = Moneta.new(store_config['adapter'], adapter_options)
end

Instance Attribute Details

#monetaObject (readonly)

Returns the value of attribute moneta.



3
4
5
# File 'lib/trocla/stores/moneta.rb', line 3

def moneta
  @moneta
end

Instance Method Details

#closeObject



15
16
17
# File 'lib/trocla/stores/moneta.rb', line 15

def close
  moneta.close
end

#formats(key) ⇒ Object



23
24
25
26
# File 'lib/trocla/stores/moneta.rb', line 23

def formats(key)
  r = moneta.fetch(key)
  r.nil? ? nil : r.keys
end

#get(key, format) ⇒ Object



19
20
21
# File 'lib/trocla/stores/moneta.rb', line 19

def get(key, format)
  moneta.fetch(key, {})[format]
end

#search(key) ⇒ Object



28
29
30
31
32
33
# File 'lib/trocla/stores/moneta.rb', line 28

def search(key)
  raise 'The search option is not available for any adapter other than Sequel or YAML' unless store_config['adapter'] == :Sequel || store_config['adapter'] == :YAML

  r = search_keys(key)
  r.empty? ? nil : r
end