Skip to content

Commit

Permalink
account for the API differences in both rail6 and rails7
Browse files Browse the repository at this point in the history
  • Loading branch information
cflipse committed Oct 26, 2023
1 parent 6c57674 commit f65d5fb
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/rom/rails/active_record/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit f65d5fb

Please sign in to comment.