otr-activerecord 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d318dcf63df4adf2773ecaea8663db39502c2a423e2367a1a0dc9552f277563
4
- data.tar.gz: ea0483713e317f4eb0b1b4e45099e9db3de30098b207b7adf64a2d29a7370616
3
+ metadata.gz: cd820c260dab9b0cbef1548223fd8c7173c5cf2995e133e32db0ce2c90c3c427
4
+ data.tar.gz: 2a170bd9fcaee46df1a0255180cc765eb4145d95fcb1ca7daf63a786cd43518d
5
5
  SHA512:
6
- metadata.gz: 8afe4f886901046296b816c50ecad5637280afbbf077a53a77c1f74a5da2073c8ba91c353fe8cf5df5239c03a5a955ca5ca13b9dd147c729d1dafe7b94f5b652
7
- data.tar.gz: 412060fba9c524ccb59acd56f13cbe8d26fcc4f0662377dadc25663b22b3954b11f10a5a8d0593e12e9fbe11e0b6b884cb0c8ce7776d9ea529147d7fbd878277
6
+ metadata.gz: c736dd5202985ab80f22318fbdab901c769e009ebc5dfb6b3de3c3be133f767e530222c231000bdef783c9fb3628cdbe69b5c1c3e9191bd1e3d1d5606debf198
7
+ data.tar.gz: 5e5bfb8062b5ab2508b5057a5b8e222a5f0034a96a3e0a9f632c74ae2e53ba05350c8d30bf84b2e47051deea66a3094dd62721afb6e4d6b731135d1491cea44b
@@ -57,18 +57,16 @@ module OTR
57
57
  # Connect to database with a yml file. Example: "config/database.yml"
58
58
  def self.configure_from_file!(path)
59
59
  raise "#{path} does not exist!" unless File.file? path
60
- ::ActiveRecord::Base.configurations =
61
- (YAML.load(ERB.new(File.read(path)).result) || {}).
62
- reduce({}) { |a, (env, config)|
63
- if config.has_key? "database"
64
- a[env] = {"migrations_paths" => ::OTR::ActiveRecord.migrations_paths}.merge config
65
- elsif env == rack_env.to_s
66
- config.each do |dbname, subconfig|
67
- a[dbname.to_sym] = {"migrations_paths" => ::OTR::ActiveRecord.migrations_paths}.merge subconfig
68
- end
60
+ result =(YAML.safe_load(ERB.new(File.read(path)).result, [], [], true) || {})
61
+ ::ActiveRecord::Base.configurations = begin
62
+ result.each do |_env, config|
63
+ if config.all? { |_, v| v.is_a?(Hash) }
64
+ config.each { |_, v| append_migration_path(v) }
65
+ else
66
+ append_migration_path(config)
69
67
  end
70
- a
71
- }
68
+ end
69
+ end
72
70
  end
73
71
 
74
72
  # Establish a connection to the given db (defaults to current rack env)
@@ -76,6 +74,11 @@ module OTR
76
74
  ::ActiveRecord::Base.establish_connection(db)
77
75
  end
78
76
 
77
+ def self.append_migration_path(config)
78
+ config['migrations_paths'] = ::OTR::ActiveRecord.migrations_paths unless config.key?('migrations_paths')
79
+ config
80
+ end
81
+
79
82
  # The current Rack environment
80
83
  def self.rack_env
81
84
  (ENV['RACK_ENV'] || ENV['RAILS_ENV'] || ENV['APP_ENV'] || ENV['OTR_ENV'] || 'development').to_sym
@@ -1,6 +1,6 @@
1
1
  module OTR
2
2
  module ActiveRecord
3
3
  # Gem version
4
- VERSION = '2.0.1'
4
+ VERSION = '2.0.2'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: otr-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-24 00:00:00.000000000 Z
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord