“acts_as_comparable” is plugin for ActiveRecord which allows you to easily compare and determine the differences between two ActiveRecord models.
class Person
acts_as_comparable :only=>\[:first_name, :last_name\]
end
joe = Person.new :first_name=>"Joe", :last_name=>"Smith"
joseph = Person.new :first_name => "Joseph", :last_name=>"Smith"
joe.same?( joseph ) # => false
joe.different?( joseph ) # => true
joe.differences( joseph ) # => {:first_name=>\["Joe", "Joseph"\]}
The usage in the above example shows the only option, but this also works with no options, the except option and also the attrsmap_ option. See it’s ruby doc for more information.
Installing as a RubyGem
gem install -r acts_as_comparable
Installing as a Plugin
Installing from a version
script/plugin install http://rails.lotswholetime.com/svn/acts_as_comparable/tags/acts_as_comparable-1.1
blog comments powered by Disqus