Class: DeltaCore::Comparator
- Inherits:
-
Object
- Object
- DeltaCore::Comparator
- Defined in:
- lib/delta_core/comparator.rb
Constant Summary collapse
- BUILT_IN_STRATEGIES =
{ quantity: Strategies::Quantity, replace: Strategies::Replace, merge: Strategies::Merge }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #compare ⇒ Object
-
#initialize(snapshot_state, current_state, config) ⇒ Comparator
constructor
A new instance of Comparator.
Constructor Details
#initialize(snapshot_state, current_state, config) ⇒ Comparator
Returns a new instance of Comparator.
15 16 17 18 19 |
# File 'lib/delta_core/comparator.rb', line 15 def initialize(snapshot_state, current_state, config) @snapshot_state = snapshot_state @current_state = current_state @config = config end |
Class Method Details
.compare(snapshot_state, current_state, config) ⇒ Object
11 12 13 |
# File 'lib/delta_core/comparator.rb', line 11 def self.compare(snapshot_state, current_state, config) new(snapshot_state, current_state, config).compare end |
Instance Method Details
#compare ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/delta_core/comparator.rb', line 21 def compare @config.mappings.reduce(DeltaResult.new) do |result, mapping| snap_coll = Array(@snapshot_state[mapping.name]) curr_coll = Array(@current_state[mapping.name]) strategy = resolve_strategy(mapping.strategy) raw = strategy.call(snap_coll, curr_coll, mapping) partial = DeltaResult.new(**raw) nested = compare_nested(snap_coll, curr_coll, mapping) result.merge(partial).merge(nested) end end |