0
# Declare and check for suffixed attribute methods.
0
- # Declare a method available for all attributes with the given suffix.
0
- # Uses method_missing and respond_to? to rewrite the method
0
+ # Declares a method available for all attributes with the given suffix.
0
+ # Uses +method_missing+ and <tt>respond_to?</tt> to rewrite the method
0
# #{attr}#{suffix}(*args, &block)
0
# attribute#{suffix}(#{attr}, *args, &block)
0
- # An attribute#{suffix} instance method must exist and accept at least
0
+ # An <tt>attribute#{suffix}</tt> instance method must exist and accept at least
0
+ # the +attr+ argument.
0
# class Person < ActiveRecord::Base
0
# attribute_method_suffix '_changed?'
0
!generated_methods.empty?
0
- # generates all the attribute related methods for columns in the database
0
- # accessors, mutators and query methods
0
+ # Generates all the attribute related methods for columns in the database
0
+ # accessors, mutators and query methods.
0
def define_attribute_methods
0
return if generated_methods?
0
columns_hash.each do |name, column|
0
- # Check to see if the method is defined in the model or any of its subclasses that also derive from ActiveRecord.
0
- # Raise DangerousAttributeError if the method is defined by ActiveRecord though.
0
+ # Checks whether the method is defined in the model or any of its subclasses
0
+ # that also derive from ActiveRecord. Raises DangerousAttributeError if the
0
+ # method is defined by Active Record though.
0
def instance_method_already_implemented?(method_name)
0
method_name = method_name.to_s
0
return true if method_name =~ /^id(=$|\?$|$)/
0
# +cache_attributes+ allows you to declare which converted attribute values should
0
# be cached. Usually caching only pays off for attributes with expensive conversion
0
- # methods, like time related columns (e.g.
created_at, updated_at).
0
+ # methods, like time related columns (e.g.
+created_at+, +updated_at+).
0
def cache_attributes(*attribute_names)
0
attribute_names.each {|attr| cached_attributes << attr.to_s}
0
- # returns the attributes which are cached.
0
- # By default time related columns with datatype <tt>:datetime, :timestamp, :time, :date</tt> are cached
0
+ # Returns the attributes which are cached. By default time related columns
0
+ # with datatype <tt>:datetime, :timestamp, :time, :date</tt> are cached.
0
columns.select{|c| attribute_types_cached_by_default.include?(c.type)}.map(&:name).to_set
0
- #
returns true if the provided attribute is being cached0
+ #
Returns +true+ if the provided attribute is being cached.0
def cache_attribute?(attr_name)
0
cached_attributes.include?(attr_name)
0
- # Allows access to the object attributes, which are held in the
@attributes hash, as though they
0
+ # Allows access to the object attributes, which are held in the
<tt>@attributes</tt> hash, as though they
0
# were first-class methods. So a Person class with a name attribute can use Person#name and
0
# Person#name= and never directly use the attributes hash -- except for multiple assigns with
0
# ActiveRecord#attributes=. A Milestone class can also ask Milestone#completed? to test that
0
- # the completed attribute is not
nil or 0.
0
+ # the completed attribute is not
+nil+ or 0.
0
# It's also possible to instantiate related objects, so a Client class belonging to the clients
0
- # table with a
master_id foreign key can instantiate master through Client#master.
0
+ # table with a
+master_id+ foreign key can instantiate master through Client#master.
0
def method_missing(method_id, *args, &block)
0
method_name = method_id.to_s
0
# Updates the attribute identified by <tt>attr_name</tt> with the specified +value+. Empty strings for fixnum and float
0
- # columns are turned into
nil.
0
+ # columns are turned into
+nil+.
0
def write_attribute(attr_name, value)
0
attr_name = attr_name.to_s
0
@attributes_cache.delete(attr_name)
0
- # A Person object with a name attribute can ask person.respond_to?("name"), person.respond_to?("name="), and
0
- # person.respond_to?("name?") which will all return true.
0
+ # A Person object with a name attribute can ask <tt>person.respond_to?("name")</tt>,
0
+ # <tt>person.respond_to?("name=")</tt>, and <tt>person.respond_to?("name?")</tt>
0
+ # which will all return +true+.
0
alias :respond_to_without_attributes? :respond_to?
0
def respond_to?(method, include_priv = false)
0
method_name = method.to_s
Comments
No one has commented yet.