From f65d5fbfe42a8d48d558df3da3b419014f45c8b4 Mon Sep 17 00:00:00 2001 From: Chris Flipse Date: Thu, 26 Oct 2023 17:23:36 -0400 Subject: [PATCH] account for the API differences in both rail6 and rails7 --- lib/rom/rails/active_record/configuration.rb | 28 ++++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/rom/rails/active_record/configuration.rb b/lib/rom/rails/active_record/configuration.rb index 3491c20..be61818 100644 --- a/lib/rom/rails/active_record/configuration.rb +++ b/lib/rom/rails/active_record/configuration.rb @@ -37,23 +37,19 @@ def initialize(env: ::Rails.env, root: ::Rails.root, configurations: ::ActiveRec # # @api private def call - specs = { default: build(default_configuration.symbolize_keys) } + specs = {} - if rails6? - configurations.configs_for(env_name: env).each do |config| - specs[config.spec_name.to_sym] = build(config.config.symbolize_keys) - end + if configurations.respond_to?(:default_hash) + specs[:default] = build(configurations.default_hash) + else + specs[:default] = build(configurations.configs_for(env_name: env).first.configuration_hash) end - specs - end - - def default_configuration - if rails6? - configurations.default_hash(env) - else - configurations.fetch(env) + configurations.configs_for(env_name: env).each do |config| + specs[config.name.to_sym] = build(config.configuration_hash) end + + specs end # Builds a configuration hash from a flat database config hash. @@ -80,8 +76,12 @@ def build(config) private + def rails7? + ::ActiveRecord::VERSION::MAJOR == 7 + end + def rails6? - ::ActiveRecord::VERSION::MAJOR >= 6 + ::ActiveRecord::VERSION::MAJOR == 6 end end end