From a3eb361d4f3d2fea7a39a97fcc798f8dd2190029 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Thu, 10 Oct 2024 16:23:22 -0400 Subject: [PATCH] Move SerializePositionalToKwargsBridge to the plugin itself --- lib/manageiq/schema/engine.rb | 3 ++- .../serialize_positional_to_kwargs_bridge.rb | 19 +++++++++++++++++++ .../serialize_positional_to_kwargs_bridge.rb | 19 ------------------- 3 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 lib/manageiq/schema/serialize_positional_to_kwargs_bridge.rb delete mode 100644 spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb diff --git a/lib/manageiq/schema/engine.rb b/lib/manageiq/schema/engine.rb index 6d2142760..fa34dd22e 100644 --- a/lib/manageiq/schema/engine.rb +++ b/lib/manageiq/schema/engine.rb @@ -9,12 +9,13 @@ class Engine < ::Rails::Engine ActiveSupport.on_load(:active_record) do require_relative 'migrate_with_cleared_schema_cache' + require_relative 'serialize_positional_to_kwargs_bridge' require_relative 'schema_statements' require_relative 'command_recorder' require_relative 'schema_dumper' ActiveRecord::Migration.prepend(MigrateWithClearedSchemaCache) - + ActiveRecord::AttributeMethods::Serialization::ClassMethods.send(:prepend, ManageIQ::Schema::SerializePositionalToKwargsBridge) ActiveRecord::ConnectionAdapters::AbstractAdapter.include(SchemaStatements) ActiveRecord::Migration::CommandRecorder.include(CommandRecorder) ActiveRecord::ConnectionAdapters::SchemaDumper.prepend(SchemaDumper) diff --git a/lib/manageiq/schema/serialize_positional_to_kwargs_bridge.rb b/lib/manageiq/schema/serialize_positional_to_kwargs_bridge.rb new file mode 100644 index 000000000..3af48bc80 --- /dev/null +++ b/lib/manageiq/schema/serialize_positional_to_kwargs_bridge.rb @@ -0,0 +1,19 @@ +module ManageIQ + module Schema + module SerializePositionalToKwargsBridge + def serialize(*args, **options) + return super if Rails.version >= "7.1" + + # For rails 7.0.x, convert 7.1+ kwargs for coder/type into the positional argument + # class_name_or_coder + if options[:coder] + args << options.delete(:coder) + elsif options[:type] + args << options.delete(:type) + end + + super(*args, **options) + end + end + end +end diff --git a/spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb b/spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb deleted file mode 100644 index b662c2faf..000000000 --- a/spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Dummy - module SerializePositionalToKwargsBridge - def serialize(*args, **options) - return super if Rails.version >= "7.1" - - # For rails 7.0.x, convert 7.1+ kwargs for coder/type into the positional argument - # class_name_or_coder - if options[:coder] - args << options.delete(:coder) - elsif options[:type] - args << options.delete(:type) - end - - super(*args, **options) - end - end -end - -ActiveRecord::AttributeMethods::Serialization::ClassMethods.send(:prepend, Dummy::SerializePositionalToKwargsBridge)