Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors in specs but still broken #1

Merged
merged 7 commits into from
Nov 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading