Class: Store::DataMapper::Memory
- Inherits:
-
Store::DataMapper
- Object
- Store::DataMapper
- Store::DataMapper::Memory
- Defined in:
- lib/store/memory.rb
Instance Method Summary collapse
- #all ⇒ Object
- #bulk_find(ids) ⇒ Object
- #count ⇒ Object
- #delete(id) ⇒ Object
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #insert(data) ⇒ Object
- #single_find(id) ⇒ Object
- #update(id, data) ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
8 9 10 11 |
# File 'lib/store/memory.rb', line 8 def initialize @items = {} @id = 0 end |
Instance Method Details
#all ⇒ Object
38 39 40 |
# File 'lib/store/memory.rb', line 38 def all collection(items.values) end |
#bulk_find(ids) ⇒ Object
34 35 36 |
# File 'lib/store/memory.rb', line 34 def bulk_find(ids) collection(items.values_at(*ids)) end |
#count ⇒ Object
42 43 44 |
# File 'lib/store/memory.rb', line 42 def count all.size end |
#delete(id) ⇒ Object
25 26 27 28 |
# File 'lib/store/memory.rb', line 25 def delete(id) items.delete(id) id end |
#insert(data) ⇒ Object
13 14 15 16 17 |
# File 'lib/store/memory.rb', line 13 def insert(data) id = next_id.to_s store(id, data) id end |
#single_find(id) ⇒ Object
30 31 32 |
# File 'lib/store/memory.rb', line 30 def single_find(id) dup(items[id]) end |
#update(id, data) ⇒ Object
19 20 21 22 23 |
# File 'lib/store/memory.rb', line 19 def update(id, data) id = id.to_s store(id, data) id end |