Class: MemoryModel::Collection::Index
- Inherits:
-
Object
- Object
- MemoryModel::Collection::Index
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- lib/memory_model/collection/index.rb,
lib/memory_model/collection/index/multi.rb,
lib/memory_model/collection/index/unique.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
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.
-
#initialize(name, options) ⇒ Index
constructor
A new instance of Index.
-
#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.
-
#where(matcher) ⇒ Object
‘where` should allow me to specify complex arguments and return an array.
Constructor Details
#initialize(name, options) ⇒ Index
Returns a new instance of Index.
35 36 37 38 39 |
# File 'lib/memory_model/collection/index.rb', line 35 def initialize(name, ) @name = name @options = @index = {} end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
30 31 32 |
# File 'lib/memory_model/collection/index.rb', line 30 def index @index end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/memory_model/collection/index.rb', line 30 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
30 31 32 |
# File 'lib/memory_model/collection/index.rb', line 30 def @options end |
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.
45 46 47 |
# File 'lib/memory_model/collection/index.rb', line 45 def create(key, item) raise NotImplementedError, "#{__method__} has not been implemented for this #{name} index" end |
#delete(key) ⇒ Object
‘delete` should find a record in the collection by its indexed_value, and remove it.
60 61 62 |
# File 'lib/memory_model/collection/index.rb', line 60 def delete(key) raise NotImplementedError, "#{__method__} has not been implemented for this #{name} index" end |
#exists?(item) ⇒ Boolean
‘exists?` return whether or not an item with the given storage id exists.
65 66 67 |
# File 'lib/memory_model/collection/index.rb', line 65 def exists?(item) raise NotImplementedError, "#{__method__} has not been implemented for this #{name} index" end |
#read(key) ⇒ Object
‘read` should find a record in the collection by its indexed_value, remove it, and add with the new value.
55 56 57 |
# File 'lib/memory_model/collection/index.rb', line 55 def read(key) raise NotImplementedError, "#{__method__} has not been implemented for this #{name} index" 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.
50 51 52 |
# File 'lib/memory_model/collection/index.rb', line 50 def update(key, item) raise NotImplementedError, "#{__method__} has not been implemented for this #{name} index" end |
#values ⇒ Object
‘values` should return the values of the index
79 80 81 |
# File 'lib/memory_model/collection/index.rb', line 79 def values raise NotImplementedError, "#{__method__} has not been implemented for this #{name} index" end |
#where(matcher) ⇒ Object
‘where` should allow me to specify complex arguments and return an array
70 71 72 73 74 75 76 |
# File 'lib/memory_model/collection/index.rb', line 70 def where(matcher) matcher_class = matcher.class.name.underscore send("where_using_#{matcher_class}", matcher) rescue NoMethodError respond_to?(:where_using_default, true) ? where_using_default(matcher) : raise(InvalidWhereQuery, matcher_class) end |