Module: Zeng::Indexer::InstanceMethods
- Defined in:
- lib/zeng/indexer.rb
Instance Attribute Summary collapse
-
#index_attrs ⇒ Object
Returns the value of attribute index_attrs.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
Instance Attribute Details
#index_attrs ⇒ Object
Returns the value of attribute index_attrs.
13 14 15 |
# File 'lib/zeng/indexer.rb', line 13 def index_attrs @index_attrs end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
12 13 14 |
# File 'lib/zeng/indexer.rb', line 12 def key @key end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
12 13 14 |
# File 'lib/zeng/indexer.rb', line 12 def values @values end |
Instance Method Details
#initialize(key, value) ⇒ Object
15 16 17 18 |
# File 'lib/zeng/indexer.rb', line 15 def initialize(key, value) @key = key @values = JSON.parse value end |
#objects ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/zeng/indexer.rb', line 24 def objects map = self index_attrs = self.index_attrs Collection.class_eval { define_method(:<<){|obj| old = map.values.assoc(obj.id) map.values.delete(old) index = index_attrs.inject({}){ |h, attr| h[attr] = obj.send(attr) if obj.respond_to?(attr) h } index.merge!(:id=>obj.id) map.values << [obj.id,index] map.save } } values = Collection.new.replace(self.values) end |
#save ⇒ Object
20 21 22 |
# File 'lib/zeng/indexer.rb', line 20 def save self.class.save(self) end |