Class: GraphMediator::Mediator::IndexedHash
- Inherits:
-
Hash
- Object
- Hash
- GraphMediator::Mediator::IndexedHash
- Defined in:
- lib/graph_mediator/mediator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #<<(ar_instance, klass, changes) ⇒ Object
- #add_to_index(changes) ⇒ Object
-
#initialize(*args, &block) ⇒ IndexedHash
constructor
A new instance of IndexedHash.
Constructor Details
#initialize(*args, &block) ⇒ IndexedHash
13 14 15 16 |
# File 'lib/graph_mediator/mediator.rb', line 13 def initialize(*args, &block) @index = {} super end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
10 11 12 |
# File 'lib/graph_mediator/mediator.rb', line 10 def index @index end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
11 12 13 |
# File 'lib/graph_mediator/mediator.rb', line 11 def klass @klass end |
Instance Method Details
#<<(ar_instance, klass, changes) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/graph_mediator/mediator.rb', line 18 def <<(ar_instance, klass, changes) add_to_index(changes) case when ar_instance.new_record? then created_array = self[:_created] ||= [] created_array << changes when ar_instance.destroyed? then destroyed_array = self[:_destroyed] ||= [] destroyed_array << ar_instance.id else self[ar_instance.id] = changes end end |
#add_to_index(changes) ⇒ Object
31 32 33 |
# File 'lib/graph_mediator/mediator.rb', line 31 def add_to_index(changes) index.merge!(changes) end |