lib/happymapper/differ.rb
# Diff is a method to find what elements and attributes have changed and
# how.It extends each element and attribute with the DiffedItem module
Diff is a method to find what elements and attributes have changed and
how.It extends each element and attribute with the DiffedItem module
Diff is a method to find what elements and attributes have changed and how . It extends each element and attribute with the DiffedItem module
def diff
      @left = DiffedItem.create(@left, @right)
      all_items.each do |item|
        lvalue = get_value(@left, item.name)
        rvalue = get_value(@right, item.name)
        next if rvalue.nil? && lvalue.nil?
        if ! item.options[:single]
          setup_element(lvalue, rvalue)
          count = [lvalue.size, (rvalue || []).size].max
          count.times do |i|
            lvalue[i] = setup_element(lvalue[i], (rvalue || [])[i])
          end
        else
          lvalue = setup_element(lvalue, rvalue)
        end
        @left.send("#{item.name}=", lvalue)
      end
      @left
    end
def diff @left = DiffedItem . create ( @left , @right ) all_items . each do | item | lvalue = get_value ( @left , item . name ) rvalue = get_value ( @right , item . name ) next if rvalue . nil? && lvalue . nil? if ! item . options [ :single ] setup_element ( lvalue , rvalue ) count = [ lvalue . size , ( rvalue || [ ] ) . size ] . max count . times do | i | lvalue [ i ] = setup_element ( lvalue [ i ] , ( rvalue || [ ] ) [ i ] ) end else lvalue = setup_element ( lvalue , rvalue ) end @left . send ( "#{item.name}=" , lvalue ) end @left end
Diff is a method to find what elements and attributes have changed and
how.It extends each element and attribute with the DiffedItem module
Diff is a method to find what elements and attributes have changed and how . It extends each element and attribute with the DiffedItem module
# setup for each element (has_one and has_many) and attribute # skip if both sides are nil # Find the side with the most items. If the right has more, the left # will be padded with UnExtendable instances