lib/acts_as_diffable.rb
# Return a hash of the different attributes between two hashes, such as
# attributes of an ActiveRecord class.
Return a hash of the different attributes between two hashes, such as
attributes of an ActiveRecord class.
Return a hash of the different attributes between two hashes such as attributes of an ActiveRecord class .
def diff(other)
          case other.class
          when self.class
            other
          else
            other = self.class.find(other)
          end
          differences = attributes_diff(self, other) || {}
          ActiveRecord::Acts::Diffable::SINGULAR_MACROS.each do |macro|
            self.class.reflect_on_all_associations(macro).each do |a|
              differences[a.name.to_s] = singular_association_diff(self, other, a.name) if a.options[:diff]
              differences.delete(a.options[:foreign_key] || "#{a.name}_id")
            end
          end
          ActiveRecord::Acts::Diffable::PLURAL_MACROS.each do |macro|
            self.class.reflect_on_all_associations(macro).each do |a|
              differences[a.name.to_s] = plural_association_diff(self, other, a.name, a.options[:diff_key]) if a.options[:diff_key]
            end
          end
          self.class.manual_diff_definitions.each{|d_name, d_props|
            if d_props[:diff_key]
              differences[d_name] = plural_association_diff(self, other, d_props[:eval], d_props[:diff_key])
            else
              differences[d_name] = singular_association_diff(self, other, d_props[:eval])
            end
          }
          remove_unchanged_entries differences
        end
def diff ( other ) case other . class when self . class other else other = self . class . find ( other ) end differences = attributes_diff ( self , other ) || { } ActiveRecord :: Acts :: Diffable :: SINGULAR_MACROS . each do | macro | self . class . reflect_on_all_associations ( macro ) . each do | a | differences [ a . name . to_s ] = singular_association_diff ( self , other , a . name ) if a . options [ :diff ] differences . delete ( a . options [ :foreign_key ] || "#{a.name}_id" ) end end ActiveRecord :: Acts :: Diffable :: PLURAL_MACROS . each do | macro | self . class . reflect_on_all_associations ( macro ) . each do | a | differences [ a . name . to_s ] = plural_association_diff ( self , other , a . name , a . options [ :diff_key ] ) if a . options [ :diff_key ] end end self . class . manual_diff_definitions . each { | d_name , d_props | if d_props [ :diff_key ] differences [ d_name ] = plural_association_diff ( self , other , d_props [ :eval ] , d_props [ :diff_key ] ) else differences [ d_name ] = singular_association_diff ( self , other , d_props [ :eval ] ) end } remove_unchanged_entries differences end
Return a hash of the different attributes between two hashes, such as
attributes of an ActiveRecord class.
Return a hash of the different attributes between two hashes such as attributes of an ActiveRecord class .
# is other an instance or just an id? # diff the top-level attributes # has_one and belongs_to associations # has_many and habtm associations # manually defined diffs
other
<not_specific>