Module | ActiveRecord::AttributeMethods::ClassMethods |
In: |
lib/active_record/attribute_methods.rb
|
Declare and check for suffixed attribute methods.
Declares 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 time related columns (e.g. created_at, updated_at).
Returns the attributes which are cached. By default time related columns with datatype :datetime, :timestamp, :time, :date are cached.
Generates all the attribute related methods for columns in the database accessors, mutators and query methods.
Checks whether the method is defined in the model or any of its subclasses that also derive from Active Record. Raises DangerousAttributeError if the method is defined by Active Record though.