Class: MemDB::IndexingObject
- Inherits:
-
Object
- Object
- MemDB::IndexingObject
- Defined in:
- lib/mem_db/indexing_object.rb
Instance Method Summary collapse
- #[](attr) ⇒ Object
- #[]=(param, value) ⇒ Object
- #assign!(params) ⇒ Object
- #delete(param) ⇒ Object
- #idx_value(idx) ⇒ Object
-
#initialize ⇒ IndexingObject
constructor
A new instance of IndexingObject.
- #prepare_attr(attr) ⇒ Object
Constructor Details
#initialize ⇒ IndexingObject
Returns a new instance of IndexingObject.
7 8 9 10 11 |
# File 'lib/mem_db/indexing_object.rb', line 7 def initialize @params = {} @attrs = {} @idx_value = {} end |
Instance Method Details
#[](attr) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/mem_db/indexing_object.rb', line 21 def [](attr) if @attrs.key?(attr) @attrs[attr] else @attrs[attr] ||= prepare_attr(attr) end end |
#[]=(param, value) ⇒ Object
29 30 31 |
# File 'lib/mem_db/indexing_object.rb', line 29 def []=(param, value) @params[param] = value end |
#assign!(params) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/mem_db/indexing_object.rb', line 13 def assign!(params) @params = params @attrs.clear @idx_value.clear self end |
#delete(param) ⇒ Object
33 34 35 36 |
# File 'lib/mem_db/indexing_object.rb', line 33 def delete(param) @params.delete(param) @attrs.delete(param) end |
#idx_value(idx) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/mem_db/indexing_object.rb', line 38 def idx_value(idx) if @idx_value.key?(idx) @idx_value[idx] else @idx_value[idx] ||= idx.value(self) end end |