aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2012-09-28 23:17:07 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2012-09-28 23:17:07 +0530
commit955a72c692a4298d238cc2e6353b9874099203f1 (patch)
tree2a05fecd15526cd0013c22e45825be1aca4844d9 /activerecord/lib/active_record/attribute_methods
parent77fbe1c0199567486c422fdf5cce49f2c11fc953 (diff)
parentcf3e760b87c49470c9a26ab3e2da67602474be1f (diff)
downloadrails-955a72c692a4298d238cc2e6353b9874099203f1.tar.gz
rails-955a72c692a4298d238cc2e6353b9874099203f1.tar.bz2
rails-955a72c692a4298d238cc2e6353b9874099203f1.zip
Merge branch 'master' of github.com:lifo/docrails
Conflicts: actionpack/lib/action_view/helpers/asset_tag_helper.rb
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r--activerecord/lib/active_record/attribute_methods/dirty.rb8
-rw-r--r--activerecord/lib/active_record/attribute_methods/primary_key.rb26
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb12
-rw-r--r--activerecord/lib/active_record/attribute_methods/serialization.rb19
-rw-r--r--activerecord/lib/active_record/attribute_methods/write.rb5
5 files changed, 40 insertions, 30 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb
index 6204e4172d..7a5bb9e863 100644
--- a/activerecord/lib/active_record/attribute_methods/dirty.rb
+++ b/activerecord/lib/active_record/attribute_methods/dirty.rb
@@ -7,7 +7,7 @@ module ActiveRecord
end
module AttributeMethods
- module Dirty
+ module Dirty # :nodoc:
extend ActiveSupport::Concern
include ActiveModel::Dirty
@@ -21,7 +21,7 @@ module ActiveRecord
end
# Attempts to +save+ the record and clears changed attributes if successful.
- def save(*) #:nodoc:
+ def save(*)
if status = super
@previously_changed = changes
@changed_attributes.clear
@@ -30,7 +30,7 @@ module ActiveRecord
end
# Attempts to <tt>save!</tt> the record and clears changed attributes if successful.
- def save!(*) #:nodoc:
+ def save!(*)
super.tap do
@previously_changed = changes
@changed_attributes.clear
@@ -38,7 +38,7 @@ module ActiveRecord
end
# <tt>reload</tt> the record and clears changed attributes.
- def reload(*) #:nodoc:
+ def reload(*)
super.tap do
@previously_changed.clear
@changed_attributes.clear
diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb
index aa6704d5c9..0857b02c8e 100644
--- a/activerecord/lib/active_record/attribute_methods/primary_key.rb
+++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -5,28 +5,29 @@ module ActiveRecord
module PrimaryKey
extend ActiveSupport::Concern
- # Returns this record's primary key value wrapped in an Array if one is available
+ # Returns this record's primary key value wrapped in an Array if one is
+ # available.
def to_key
key = self.id
[key] if key
end
- # Returns the primary key value
+ # Returns the primary key value.
def id
read_attribute(self.class.primary_key)
end
- # Sets the primary key value
+ # Sets the primary key value.
def id=(value)
write_attribute(self.class.primary_key, value) if self.class.primary_key
end
- # Queries the primary key value
+ # Queries the primary key value.
def id?
query_attribute(self.class.primary_key)
end
- # Returns the primary key value before type cast
+ # Returns the primary key value before type cast.
def id_before_type_cast
read_attribute_before_type_cast(self.class.primary_key)
end
@@ -52,14 +53,16 @@ module ActiveRecord
super && !ID_ATTRIBUTE_METHODS.include?(method_name)
end
- # Defines the primary key field -- can be overridden in subclasses. Overwriting will negate any effect of the
- # primary_key_prefix_type setting, though.
+ # Defines the primary key field -- can be overridden in subclasses.
+ # Overwriting will negate any effect of the +primary_key_prefix_type+
+ # setting, though.
def primary_key
@primary_key = reset_primary_key unless defined? @primary_key
@primary_key
end
- # Returns a quoted version of the primary key name, used to construct SQL statements.
+ # Returns a quoted version of the primary key name, used to construct
+ # SQL statements.
def quoted_primary_key
@quoted_primary_key ||= connection.quote_column_name(primary_key)
end
@@ -92,16 +95,17 @@ module ActiveRecord
# Sets the name of the primary key column.
#
# class Project < ActiveRecord::Base
- # self.primary_key = "sysid"
+ # self.primary_key = 'sysid'
# end
#
- # You can also define the primary_key method yourself:
+ # You can also define the +primary_key+ method yourself:
#
# class Project < ActiveRecord::Base
# def self.primary_key
- # "foo_" + super
+ # 'foo_' + super
# end
# end
+ #
# Project.primary_key # => "foo_id"
def primary_key=(value)
@primary_key = value && value.to_s
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index 1a4cb25dd7..6213b5dcd5 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -14,9 +14,10 @@ module ActiveRecord
end
module ClassMethods
- # +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+).
+ # +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+).
def cache_attributes(*attribute_names)
cached_attributes.merge attribute_names.map { |attr| attr.to_s }
end
@@ -65,8 +66,9 @@ module ActiveRecord
ActiveRecord::Model.attribute_types_cached_by_default = ATTRIBUTE_TYPES_CACHED_BY_DEFAULT
- # Returns the value of the attribute identified by <tt>attr_name</tt> after it has been typecast (for example,
- # "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)).
+ # Returns the value of the attribute identified by <tt>attr_name</tt> after
+ # it has been typecast (for example, "2004-12-12" in a data column is cast
+ # to a date object, like Date.new(2004, 12, 12)).
def read_attribute(attr_name)
return unless attr_name
name_sym = attr_name.to_sym
diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb
index 6395f92b4b..9994a81ede 100644
--- a/activerecord/lib/active_record/attribute_methods/serialization.rb
+++ b/activerecord/lib/active_record/attribute_methods/serialization.rb
@@ -4,17 +4,19 @@ module ActiveRecord
extend ActiveSupport::Concern
included do
- # Returns a hash of all the attributes that have been specified for serialization as
- # keys and their class restriction as values.
+ # Returns a hash of all the attributes that have been specified for
+ # serialization as keys and their class restriction as values.
class_attribute :serialized_attributes, instance_accessor: false
self.serialized_attributes = {}
end
module ClassMethods
- # If you have an attribute that needs to be saved to the database as an object, and retrieved as the same object,
- # then specify the name of that attribute using this method and it will be handled automatically.
- # The serialization is done through YAML. If +class_name+ is specified, the serialized object must be of that
- # class on retrieval or SerializationTypeMismatch will be raised.
+ # If you have an attribute that needs to be saved to the database as an
+ # object, and retrieved as the same object, then specify the name of that
+ # attribute using this method and it will be handled automatically. The
+ # serialization is done through YAML. If +class_name+ is specified, the
+ # serialized object must be of that class on retrieval or
+ # <tt>SerializationTypeMismatch</tt> will be raised.
#
# ==== Parameters
#
@@ -22,7 +24,8 @@ module ActiveRecord
# * +class_name+ - Optional, class name that the object type should be equal to.
#
# ==== Example
- # # Serialize a preferences attribute
+ #
+ # # Serialize a preferences attribute.
# class User < ActiveRecord::Base
# serialize :preferences
# end
@@ -60,7 +63,7 @@ module ActiveRecord
end
end
- class Attribute < Struct.new(:coder, :value, :state)
+ class Attribute < Struct.new(:coder, :value, :state) # :nodoc:
def unserialized_value
state == :serialized ? unserialize : value
end
diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb
index 5a39cb0125..6eb9e25fd9 100644
--- a/activerecord/lib/active_record/attribute_methods/write.rb
+++ b/activerecord/lib/active_record/attribute_methods/write.rb
@@ -20,8 +20,9 @@ module ActiveRecord
end
end
- # Updates the attribute identified by <tt>attr_name</tt> with the specified +value+. Empty strings
- # for fixnum and float columns are turned into +nil+.
+ # Updates the attribute identified by <tt>attr_name</tt> with the
+ # specified +value+. Empty strings for fixnum and float columns are
+ # turned into +nil+.
def write_attribute(attr_name, value)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id' && self.class.primary_key