Permalink
Browse files

update AR::AttributeMethods::BeforeTypeCast docs [ci skip]

  • Loading branch information...
Francesco Rodriguez
Francesco Rodriguez committed Oct 21, 2012
1 parent 06e908c commit c6fb832fe883ac996c0fa773ee2b5c9fdc2c9f62
Showing with 18 additions and 0 deletions.
  1. +18 −0 activerecord/lib/active_record/attribute_methods/before_type_cast.rb
@@ -7,11 +7,29 @@ module BeforeTypeCast
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

0 comments on commit c6fb832

Please sign in to comment.