Class: Moneta::Adapters::DataMapper
- Inherits:
-
Object
- Object
- Moneta::Adapters::DataMapper
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/datamapper.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(options = {}) ⇒ DataMapper
constructor
A new instance of DataMapper.
- #key?(key) ⇒ Boolean
- #store(key, value) ⇒ Object
Methods included from Defaults
Constructor Details
#initialize(options = {}) ⇒ DataMapper
Returns a new instance of DataMapper.
29 30 31 32 33 34 |
# File 'lib/moneta/adapters/datamapper.rb', line 29 def initialize( = {}) @repository = .delete(:repository) || :moneta ::DataMapper.setup(@repository, [:setup]) MonetaHash.auto_upgrade!(@repository) @hash = MonetaHash end |
Instance Method Details
#[](key) ⇒ Object
40 41 42 |
# File 'lib/moneta/adapters/datamapper.rb', line 40 def [](key) repository_context { @hash.value(key_for(key)) } end |
#clear ⇒ Object
66 67 68 |
# File 'lib/moneta/adapters/datamapper.rb', line 66 def clear(*) repository_context { @hash.all.destroy! } end |
#delete(key) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/moneta/adapters/datamapper.rb', line 56 def delete(key, *) string_key = key_for(key) repository_context { value = self[key] @hash.all(:the_key => string_key).destroy! value } end |
#key?(key) ⇒ Boolean
36 37 38 |
# File 'lib/moneta/adapters/datamapper.rb', line 36 def key?(key, *) repository_context { !!@hash.get(key_for(key)) } end |
#store(key, value) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/moneta/adapters/datamapper.rb', line 44 def store(key, value, *) string_key = key_for(key) repository_context { obj = @hash.get(string_key) if obj obj.update(string_key, value) else @hash.create(:the_key => string_key, :value => value) end } end |