Module: ActiveRecord::AttributeMethods::ClassMethods

Module | ActiveRecord::AttributeMethods::ClassMethods
In: | lib/active_record/attribute_methods.rb

Declare and check for suffixed attribute methods.

### Methods

attribute_method_suffix cache_attribute? cache_attributes cached_attributes define_attribute_methods define_read_methods generated_methods? instance_method_already_implemented? match_attribute_method?

### Public Instance methods

attribute_method_suffix(*suffixes)

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_attribute?(attr_name)

Returns `true` if the provided attribute is being cached.

cache_attributes(*attribute_names)

`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`).

cached_attributes()

Returns the attributes which are cached. By default time related columns with datatype `:datetime, :timestamp, :time, :date` are cached.

define_attribute_methods()

Generates all the attribute related methods for columns in the database accessors, mutators and query methods.

define_read_methods()

Alias for define_attribute_methods

generated_methods?()
instance_method_already_implemented?(method_name)

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.

match_attribute_method?(method_name)

Returns MatchData if method_name is an attribute method.

[Validate]