diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-15 14:01:33 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-15 14:02:30 -0800 |
commit | 6bfa846a2cc950bbb3d8b30f076589a60f38b821 (patch) | |
tree | 451ed3751cc0c8c1827820cfda253d51f447ecd7 /activerecord/lib/active_record/serializers | |
parent | 96bae30538951367a82235785e7dba3577b50a5a (diff) | |
download | rails-6bfa846a2cc950bbb3d8b30f076589a60f38b821.tar.gz rails-6bfa846a2cc950bbb3d8b30f076589a60f38b821.tar.bz2 rails-6bfa846a2cc950bbb3d8b30f076589a60f38b821.zip |
dry up compute type in attribute
Diffstat (limited to 'activerecord/lib/active_record/serializers')
-rw-r--r-- | activerecord/lib/active_record/serializers/xml_serializer.rb | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb index 0746908131..8c4adf7116 100644 --- a/activerecord/lib/active_record/serializers/xml_serializer.rb +++ b/activerecord/lib/active_record/serializers/xml_serializer.rb @@ -226,23 +226,17 @@ module ActiveRecord #:nodoc: class Attribute < ActiveModel::Serializers::Xml::Serializer::Attribute #:nodoc: def compute_type - case - when @serializable.class.serialized_attributes.has_key?(name) - type = super - when @serializable.class.columns_hash.has_key?(name) - type = @serializable.class.columns_hash[name].type - else - type = NilClass - end + klass = @serializable.class + type = if klass.serialized_attributes.key?(name) + super + elsif klass.columns_hash.key?(name) + klass.columns_hash[name].type + else + NilClass + end - case type - when :text - :string - when :time - :datetime - else - type - end + { :text => :string, + :time => :datetime }[type] || type end protected :compute_type end |