aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-10-21 14:06:53 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-10-21 14:09:52 -0500
commitc6fb832fe883ac996c0fa773ee2b5c9fdc2c9f62 (patch)
tree08146cca0eaf7842a3cc238b2f25d52fd4ae887b /activerecord
parent06e908c4e13a0f87f05f6115e13e6f5b8d20d499 (diff)
downloadrails-c6fb832fe883ac996c0fa773ee2b5c9fdc2c9f62.tar.gz
rails-c6fb832fe883ac996c0fa773ee2b5c9fdc2c9f62.tar.bz2
rails-c6fb832fe883ac996c0fa773ee2b5c9fdc2c9f62.zip
update AR::AttributeMethods::BeforeTypeCast docs [ci skip]
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_methods/before_type_cast.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/before_type_cast.rb b/activerecord/lib/active_record/attribute_methods/before_type_cast.rb
index d4f529acbf..030972fc8a 100644
--- a/activerecord/lib/active_record/attribute_methods/before_type_cast.rb
+++ b/activerecord/lib/active_record/attribute_methods/before_type_cast.rb
@@ -7,11 +7,29 @@ module ActiveRecord
attribute_method_suffix "_before_type_cast"
end
+ # Returns the value of the attribuet identified by +attr_name+ before
+ # typecasting and deserialization.
+ #
+ # class Task < ActiveRecord::Base
+ # end
+ #
+ # task = Task.new(id: '1', completed_on: '2012-10-21')
+ # task.read_attribute('id') # => 1
+ # task.read_attribute_before_type_cast('id') # => '1'
+ # task.read_attribute('completed_on') # => Sun, 21 Oct 2012
+ # task.read_attribute_before_type_cast('completed_on') # => "2012-10-21"
def read_attribute_before_type_cast(attr_name)
@attributes[attr_name]
end
# Returns a hash of attributes before typecasting and deserialization.
+ #
+ # class Task < ActiveRecord::Base
+ # end
+ #
+ # task = Task.new(title: nil, is_done: true, completed_on: '2012-10-21')
+ # task.attributes_before_type_cast
+ # # => {"id"=>nil, "title"=>nil, "is_done"=>true, "completed_on"=>"2012-10-21", "created_at"=>nil, "updated_at"=>nil}
def attributes_before_type_cast
@attributes
end