Class: Zonesync::Diff
- Inherits:
-
Struct
- Object
- Struct
- Zonesync::Diff
- Defined in:
- lib/zonesync/diff.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#to ⇒ Object
Returns the value of attribute to.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from
4 5 6 |
# File 'lib/zonesync/diff.rb', line 4 def from @from end |
#to ⇒ Object
Returns the value of attribute to
4 5 6 |
# File 'lib/zonesync/diff.rb', line 4 def to @to end |
Class Method Details
.call(from:, to:) ⇒ Object
5 6 7 |
# File 'lib/zonesync/diff.rb', line 5 def self.call(from:, to:) new(from, to).call end |
Instance Method Details
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/zonesync/diff.rb', line 9 def call changes = ::Diff::LCS.sdiff(from.diffable_records, to.diffable_records) changes.map do |change| case change.action when "-" [:remove, [change.old_element.to_h]] when "!" [:change, [change.old_element.to_h, change.new_element.to_h]] when "+" [:add, [change.new_element.to_h]] end end.compact end |