aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-06-14 16:34:58 +0200
committerYves Senn <yves.senn@gmail.com>2014-06-14 16:34:58 +0200
commit69807afdd0e39025230c7c74b09db01f0cc160d6 (patch)
tree55ce8558ed72a8bba13c230d4606d113c44e2f39 /activerecord/lib
parent64220a1de3574ceab70d3ed06e83ee8711ac2204 (diff)
parent2df1540143f1a57ab7aae8ff926266cc233292c5 (diff)
downloadrails-69807afdd0e39025230c7c74b09db01f0cc160d6.tar.gz
rails-69807afdd0e39025230c7c74b09db01f0cc160d6.tar.bz2
rails-69807afdd0e39025230c7c74b09db01f0cc160d6.zip
Merge pull request #15704 from sgrif/sg-deprecate-serialized
Deprecate `serialized_attributes` without replacement
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/attribute_methods/serialization.rb33
1 files changed, 17 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb
index cec50f62a3..d06d5bcd92 100644
--- a/activerecord/lib/active_record/attribute_methods/serialization.rb
+++ b/activerecord/lib/active_record/attribute_methods/serialization.rb
@@ -3,20 +3,7 @@ module ActiveRecord
module Serialization
extend ActiveSupport::Concern
- included do
- # Returns a hash of all the attributes that have been specified for
- # serialization as keys and their class restriction as values.
- class_attribute :serialized_attributes, instance_accessor: false
- self.serialized_attributes = {}
- end
-
module ClassMethods
- ##
- # :method: serialized_attributes
- #
- # Returns a hash of all the attributes that have been specified for
- # serialization as keys and their class restriction as values.
-
# If you have an attribute that needs to be saved to the database as an
# object, and retrieved as the same object, then specify the name of that
# attribute using this method and it will be handled automatically. The
@@ -59,10 +46,24 @@ module ActiveRecord
decorate_attribute_type(attr_name, :serialize) do |type|
Type::Serialized.new(type, coder)
end
+ end
+
+ def serialized_attributes
+ ActiveSupport::Deprecation.warn(<<-WARNING.strip_heredoc)
+ `serialized_attributes` is deprecated, and will be removed in Rails 5.0.
+ If you need to access the serialization behavior, you can do:
+
+ #{self.class.name}.column_for_attribute('foo').type_cast_for_database(value)
+
+ or
- # merge new serialized attribute and create new hash to ensure that each class in inheritance hierarchy
- # has its own hash of own serialized attributes
- self.serialized_attributes = serialized_attributes.merge(attr_name.to_s => coder)
+ #{self.class.name}.column_for_attribute('foo').type_cast_from_database(value)
+ WARNING
+ @serialized_attributes ||= Hash[
+ columns.select { |t| t.cast_type.is_a?(Type::Serialized) }.map { |c|
+ [c.name, c.cast_type.coder]
+ }
+ ]
end
end
end