diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-22 16:25:40 -0600 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-26 06:45:57 -0300 |
commit | 14b1208dd313f643f72aa2d92874198342e9fe14 (patch) | |
tree | 82af9d0a1dbcaafb4061c50ffa6d1a595d339e95 /activerecord/lib/active_record/attribute_set.rb | |
parent | 2571c3f415ac0c6eacedbc199e31b1c77e7bacc4 (diff) | |
download | rails-14b1208dd313f643f72aa2d92874198342e9fe14.tar.gz rails-14b1208dd313f643f72aa2d92874198342e9fe14.tar.bz2 rails-14b1208dd313f643f72aa2d92874198342e9fe14.zip |
Encapsulate the creation of `Attribute` objects
This will make it less painful to add additional properties, which
should persist across writes, such as `name`.
Conflicts:
activerecord/lib/active_record/attribute_set.rb
Diffstat (limited to 'activerecord/lib/active_record/attribute_set.rb')
-rw-r--r-- | activerecord/lib/active_record/attribute_set.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_set.rb b/activerecord/lib/active_record/attribute_set.rb index 68382756a4..65e15b16dd 100644 --- a/activerecord/lib/active_record/attribute_set.rb +++ b/activerecord/lib/active_record/attribute_set.rb @@ -2,7 +2,7 @@ require 'active_record/attribute_set/builder' module ActiveRecord class AttributeSet # :nodoc: - delegate :[], :[]=, to: :attributes + delegate :[], to: :attributes delegate :keys, to: :initialized_attributes def initialize(attributes) @@ -31,6 +31,14 @@ module ActiveRecord end end + def write_from_database(name, value) + attributes[name] = self[name].with_value_from_database(value) + end + + def write_from_user(name, value) + attributes[name] = self[name].with_value_from_user(value) + end + def freeze @attributes.freeze super |