diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-31 15:17:31 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-02-07 13:51:52 -0800 |
commit | 9c07e389be340e4d25298148cf39d10218ffb1a0 (patch) | |
tree | c2fcf4bbab2c702c065cf515c5f894bcf1e27f1d /activerecord/lib/active_record/attribute_methods | |
parent | ee161d1bc01a761abf5473d5a8d53f8684be93e9 (diff) | |
download | rails-9c07e389be340e4d25298148cf39d10218ffb1a0.tar.gz rails-9c07e389be340e4d25298148cf39d10218ffb1a0.tar.bz2 rails-9c07e389be340e4d25298148cf39d10218ffb1a0.zip |
moved attribute translation to an object
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/read.rb | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index 6d36e6a004..66f4b0b6c6 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -1,3 +1,5 @@ +require 'active_record/attributes/translator' + module ActiveRecord module AttributeMethods module Read @@ -126,28 +128,20 @@ module ActiveRecord self.class.type_cast_attribute(attr_name, @attributes, @attributes_cache) end - private - def cached_cast_attribute(attr_name, method) - @attributes_cache[attr_name] ||= cast_attribute(attr_name, method) - end - - def cast_attribute(attr_name, method) - v = @attributes.fetch(attr_name) { missing_attribute(attr_name, caller) } - v && send(method, attr_name, v) - end - def cast_serialized(attr_name, value) - value.unserialized_value + def attribute_translator + Attributes::Translator.new(@attributes, @columns_hash) end - def cast_tz_conversion(attr_name, value) - value = cast_column(attr_name, value) - value.acts_like?(:time) ? value.in_time_zone : value + def cached_cast_attribute(attr_name, method) + @attributes_cache[attr_name] ||= cast_attribute(attr_name, method) end - def cast_column(attr_name, value) - @columns_hash[attr_name].type_cast value + def cast_attribute(attr_name, method) + attribute_translator.cast_attribute(attr_name, method) do + missing_attribute(attr_name, caller) + end end def attribute(attribute_name) |