Skip to content

Commit

Permalink
Fix errors in specs but still broken
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoodrow authored Nov 12, 2023
1 parent c1329cf commit 31b3ffb
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/patches/active_record/rails7_1/serialization.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
module Globalize
module AttributeMethods
module Serialization
def serialize(attr_name, type: Object, **options)
super(attr_name, type: type, **options)
def serialize(attr_name, class_name_or_coder = Object, **options)
if class_name_or_coder == ::JSON || [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) }
options = options.merge(coder: class_name_or_coder, type: Object)
else
options = options.merge(code: default_column_serializer, type: class_name_or_coder)
end

coder = if type == ::JSON
super(attr_name, **options)

coder = if options[:coder] == ::JSON
::ActiveRecord::Coders::JSON
elsif [:load, :dump].all? { |x| type.respond_to?(x) }
type
elsif options.key?(:coder)
if coder.respond_to?(:new) && !coder.respond_to?(:load)
coder.new(attr_name, type)
else
options[:coder]
end
else
::ActiveRecord::Coders::YAMLColumn.new(attr_name, type)
::ActiveRecord::Coders::YAMLColumn.new(attr_name, options[:type], **(options.fetch(:yaml, {})))
end

self.globalize_serialized_attributes = globalize_serialized_attributes.dup
Expand Down

0 comments on commit 31b3ffb

Please sign in to comment.