Sha256: f9e3b72c55b8d4ff66e79694855d8bbacb32725e2ffcebe78da8352e9673d7da

Contents?: true

Size: 594 Bytes

Versions: 2

Compression:

Stored size: 594 Bytes

Contents

require "diff/lcs"

module Zonesync
  class Diff < Struct.new(:from, :to)
    def self.call(from:, to:)
      new(from, to).call
    end

    def call
      changes = ::Diff::LCS.sdiff(from, to)
      changes.map do |change|
        case change.action
        when "-"
          [:remove, [change.old_element]]
        when "!"
          [:change, [change.old_element, change.new_element]]
        when "+"
          [:add, [change.new_element]]
        end
      end.compact.sort_by do |operation|
        operation.first
      end.reverse # perform remove operations first
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zonesync-0.9.0 lib/zonesync/diff.rb
zonesync-0.8.0 lib/zonesync/diff.rb