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