Class: MemoryModel::Collection::Index::Multi
- Inherits:
-
MemoryModel::Collection::Index
- Object
- MemoryModel::Collection::Index
- MemoryModel::Collection::Index::Multi
- Defined in:
- lib/memory_model/collection/index/multi.rb
Instance Attribute Summary
Attributes inherited from MemoryModel::Collection::Index
Instance Method Summary collapse
-
#create(key, item) ⇒ Object
‘create` should implement creating a new record, raising an error if an item with the matching storage id already exists in the index.
-
#delete(key) ⇒ Object
‘delete` should find a record in the collection by its indexed_value, and remove it.
-
#exists?(item) ⇒ Boolean
‘exists?` return whether or not an item with the given storage id exists.
-
#read(key) ⇒ Object
‘read` should find a record in the collection by its indexed_value, remove it, and add with the new value.
-
#update(key, item) ⇒ Object
‘update` should find a record in the collection by its storage_id, remove it, and add with the new value.
-
#values ⇒ Object
‘values` should return the values of the index.
Methods inherited from MemoryModel::Collection::Index
Constructor Details
This class inherits a constructor from MemoryModel::Collection::Index
Instance Method Details
#create(key, item) ⇒ Object
‘create` should implement creating a new record, raising an error if an item with the matching storage id already exists in the index.
8 9 10 |
# File 'lib/memory_model/collection/index/multi.rb', line 8 def create(key, item) insert_into_key(key, item) end |
#delete(key) ⇒ Object
‘delete` should find a record in the collection by its indexed_value, and remove it.
25 26 27 |
# File 'lib/memory_model/collection/index/multi.rb', line 25 def delete(key) index.values.map { |refs| refs.delete key } end |
#exists?(item) ⇒ Boolean
‘exists?` return whether or not an item with the given storage id exists.
30 31 32 |
# File 'lib/memory_model/collection/index/multi.rb', line 30 def exists?(item) index.values.any? { |refs| refs.has_key? item.uuid } end |
#read(key) ⇒ Object
‘read` should find a record in the collection by its indexed_value, remove it, and add with the new value.
20 21 22 |
# File 'lib/memory_model/collection/index/multi.rb', line 20 def read(key) index[key].first end |
#update(key, item) ⇒ Object
‘update` should find a record in the collection by its storage_id, remove it, and add with the new value.
13 14 15 16 17 |
# File 'lib/memory_model/collection/index/multi.rb', line 13 def update(key, item) raise(RecordNotInIndexError, [self, item]) unless exists? item delete(item) create(key, item) end |
#values ⇒ Object
‘values` should return the values of the index
35 36 37 |
# File 'lib/memory_model/collection/index/multi.rb', line 35 def values index.values.map(&:values) end |