Module | ActiveRecord::AttributeMethods::ClassMethods |
In: |
lib/active_record/attribute_methods.rb
|
Declare and check for suffixed attribute methods.
Declare a method available for all attributes with the given suffix. Uses method_missing and respond_to? to rewrite the method
#{attr}#{suffix}(*args, &block)
to
attribute#{suffix}(#{attr}, *args, &block)
An attribute#{suffix} instance method must exist and accept at least the attr argument.
For example:
class Person < ActiveRecord::Base attribute_method_suffix '_changed?' private def attribute_changed?(attr) ... end end person = Person.find(1) person.name_changed? # => false person.name = 'Hubert' person.name_changed? # => true
cache_attributes allows you to declare which converted attribute values should be cached. Usually caching only pays off for attributes with expensive conversion methods, like date columns (e.g. created_at, updated_at).
generates all the attribute related methods for columns in the database accessors, mutators and query methods
Check to see if the method is defined in the model or any of its subclasses that also derive from ActiveRecord. Raise DangerousAttributeError if the method is defined by ActiveRecord though.