Module: ActiveRecord::Acts::Comparable

Defined in:
lib/acts_as_comparable/acts_as_comparable.rb

Overview

acts_as_comparable

acts_as_comparable provides comparison to ActiveRecord models. It allows you to capture what fields are different, as well as easy access to those diferrent values.

class MyModel < ActiveRecord::Base
acts_as_comparable
end

EXAMPLES

# default options which treats all fields as comparable
class Person < ActiveRecord::Base
acts_as_comparable
end

# specifying which fields that should act as comparable
class Person < ActiveRecord::Base
  acts_as_comparable :only => [ :first_name, :last_name, :age ]
end

# specifying which fields shouldn't act as comparable
class Person < ActiveRecord::Base
  acts_as_comparable :except => [ :eyecolor ]
end

# specifying fields which compare to another field on the same model
class  < ActiveRecord::Base
  acts_as_comparable :attrs_map => { :accountno => :parent_accountno }
end

See unit tests for more usage examples.

AUTHORS

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



42
43
44
# File 'lib/acts_as_comparable/acts_as_comparable.rb', line 42

def self.included( base )
  base.extend ClassMethods
end