vendor/plugins/acts_as_comparable/lib/acts_as_comparable/acts_as_comparable.rb
# Returns a hash of field to value mappings which signify the differences between
# this model object and the passed in +other+ model object given an optional
# set of options. Returns an empty hash if there are no comparable differences.
#
# The value of the field to value mappings is an array of the values that differ.
#
# == Arguments
# * other - another ActiveRecord model to compare this model against
# * options - a hash of options. All options for ActiveRecord::Acts::Comparable::ClassMethods.acts_as_comparable apply.
#
# == Example
#
#  class Pet < ActiveRecord::Base ; end
# 
#  pet1 = Pet.new :id=>1, :name=>"dog", :value=>"Tiny"
#  pet2 = Pet.new :id=>5, :name=>"cat", :value=>"Norm"
#
#  differences = pet1.differences(pet2)
#  #  => {:value=>["Tiny", "Norm"], :name=>["dog", "cat"], :id=>[1, 5]}
#
Returns a hash of field to value mappings which signify the differences between
this model object and the passed in +other+ model object given an optional
set of options. Returns an empty hash if there are no comparable differences.

The value of the field to value mappings is an array of the values that differ.

Arguments
other - another ActiveRecord model to compare this model against
options - a hash of options.

Example

class Pet < ActiveRecord::Base ; end




Returns a hash of field to value mappings which signify the differences between this model object and the passed in + other + model object given an optional set of options . Returns an empty hash if there are no comparable differences . The value of the field to value mappings is an array of the values that differ . Arguments other - another ActiveRecord model to compare this model against options - a hash of options . Example class Pet < ActiveRecord :: Base ; end
def differences( other = nil, options = nil )
      other ||= self.new_record? ? self.class.new : self.class.find( self.id )
      diffs = {}
      comparable_attributes_for( options ).each_pair do |attr, action|
        unless self.send( attr ) == other.send( attr )
          if action.is_a? Proc
            diffs[attr] = [ action.call( self ), action.call( other ) ]
          else
            diffs[attr] = [ self.send( attr ), other.send( attr ) ]
          end
        end
      end
      diffs.symbolize_keys
    end
def differences ( other = nil , options = nil ) other ||= self . new_record? ? self . class . new : self . class . find ( self . id ) diffs = { } comparable_attributes_for ( options ) . each_pair do | attr , action | unless self . send ( attr ) == other . send ( attr ) if action . is_a? Proc diffs [ attr ] = [ action . call ( self ) , action . call ( other ) ] else diffs [ attr ] = [ self . send ( attr ) , other . send ( attr ) ] end end end diffs . symbolize_keys end
Returns a hash of field to value mappings which signify the differences between
this model object and the passed in +other+ model object given an optional
set of options.
Returns a hash of field to value mappings which signify the differences between this model object and the passed in + other + model object given an optional set of options .
other
<not_specific>
options
<not_specific>