Skip to content

Commit d1ee9cc

Browse files
committed
and finally, a cleaner iteration
1 parent 9c80902 commit d1ee9cc

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

lib/rom/rails/active_record/configuration.rb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@ def call
4040
specs = {}
4141

4242
configurations.configs_for(env_name: env).each do |config|
43-
name = config.respond_to?(:spec_name) ? config.spec_name : config.name
44-
hash = config.respond_to?(:configuration_hash) ? config.configuration_hash : config.config
43+
if config.respond_to?(:configuration_hash)
44+
name, hash = [config.name, config.configuration_hash]
45+
else # Rails 6.0
46+
name, hash = [config.spec_name, config.config]
47+
end
4548

46-
specs[:default] ||= build(hash.symbolize_keys)
47-
specs[name.to_sym] = build(hash.symbolize_keys)
49+
specs[:default] ||= hash
50+
specs[name.to_sym] = hash
4851
end
4952

50-
specs
53+
specs.transform_values { |hash| build hash.symbolize_keys }
5154
end
5255

5356
# Builds a configuration hash from a flat database config hash.
@@ -71,16 +74,6 @@ def build(config)
7174
uri = uri_builder.build(adapter, uri_options)
7275
{ uri: uri, options: other_options }
7376
end
74-
75-
private
76-
77-
def rails7?
78-
::ActiveRecord::VERSION::MAJOR == 7
79-
end
80-
81-
def rails6?
82-
::ActiveRecord::VERSION::MAJOR == 6
83-
end
8477
end
8578
end
8679
end

0 commit comments

Comments
 (0)