Class: Igniter::Extensions::Contracts::Dataflow::AggregateState
- Inherits:
-
Object
- Object
- Igniter::Extensions::Contracts::Dataflow::AggregateState
- Defined in:
- lib/igniter/extensions/contracts/dataflow/aggregate_state.rb
Instance Method Summary collapse
- #apply_diff!(diff, collection_result) ⇒ Object
-
#initialize(operator) ⇒ AggregateState
constructor
A new instance of AggregateState.
- #value ⇒ Object
Constructor Details
#initialize(operator) ⇒ AggregateState
Returns a new instance of AggregateState.
8 9 10 11 12 |
# File 'lib/igniter/extensions/contracts/dataflow/aggregate_state.rb', line 8 def initialize(operator) @operator = operator @contributions = {} @accum = operator.initial end |
Instance Method Details
#apply_diff!(diff, collection_result) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/igniter/extensions/contracts/dataflow/aggregate_state.rb', line 14 def apply_diff!(diff, collection_result) diff.changed.each do |key| retract!(key) contribute!(key, collection_result[key]) end diff.added.each do |key| contribute!(key, collection_result[key]) end diff.removed.each do |key| retract!(key) end end |
#value ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/igniter/extensions/contracts/dataflow/aggregate_state.rb', line 29 def value if @operator.recompute @operator.finalize.call(nil, @contributions) else @operator.finalize.call(@accum, @contributions.size) end end |