diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-26 06:26:26 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-26 06:26:26 -0300 |
commit | e1ad3ed7736d5e01455f881dff42d6bef54d8978 (patch) | |
tree | a36ac8c8ce9c16a0f559be4cccd9ffaa39cb03b5 /activerecord/lib | |
parent | 18def156ba01f33255e09f18975c26b650975262 (diff) | |
parent | 3ea9a88d803d7fd1bb0de649f7237fca0200efe3 (diff) | |
download | rails-e1ad3ed7736d5e01455f881dff42d6bef54d8978.tar.gz rails-e1ad3ed7736d5e01455f881dff42d6bef54d8978.tar.bz2 rails-e1ad3ed7736d5e01455f881dff42d6bef54d8978.zip |
Merge pull request #15846 from sgrif/sg-attributes-before-type-cast
Move `attributes_before_type_cast` to `AttributeSet`
Conflicts:
activerecord/lib/active_record/attribute_set.rb
activerecord/test/cases/attribute_set_test.rb
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/before_type_cast.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_set.rb | 6 |
2 files changed, 6 insertions, 2 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 9ee9a7815f..fd61febd57 100644 --- a/activerecord/lib/active_record/attribute_methods/before_type_cast.rb +++ b/activerecord/lib/active_record/attribute_methods/before_type_cast.rb @@ -57,7 +57,7 @@ module ActiveRecord # 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.each_with_object({}) { |(k, v), h| h[k] = v.value_before_type_cast } + @attributes.values_before_type_cast end private diff --git a/activerecord/lib/active_record/attribute_set.rb b/activerecord/lib/active_record/attribute_set.rb index ed2500a675..99fc9b6ac6 100644 --- a/activerecord/lib/active_record/attribute_set.rb +++ b/activerecord/lib/active_record/attribute_set.rb @@ -1,11 +1,15 @@ module ActiveRecord class AttributeSet # :nodoc: - delegate :[], :[]=, :fetch, :include?, :keys, :each_with_object, to: :attributes + delegate :[], :[]=, :fetch, :include?, :keys, to: :attributes def initialize(attributes) @attributes = attributes end + def values_before_type_cast + attributes.each_with_object({}) { |(k, v), h| h[k] = v.value_before_type_cast } + end + def to_hash attributes.each_with_object({}) { |(k, v), h| h[k] = v.value } end |