db_charmer_env_urls 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 3efac3c3e1818b4ff725a815a686d846c6ef0eae
4
- data.tar.gz: 5aedc1f04458a97a421d095fa66e025832a9af7a
3
+ metadata.gz: 6865fc7fc3e5d23b7ee5ed5d79adaa9856b34703
4
+ data.tar.gz: 20e510bf10d8ea31a735fa77a724c1f7744c1f63
5
5
  SHA512:
6
- metadata.gz: 70a2837e4e4b2527a182fd0bb97c30b030c28dd2a60f16dac81cd0f6000e507a11bf76b1dcba0c4dbabab31a2270b53239549370af219d2010a274df86557cf8
7
- data.tar.gz: dbc186e46a4cfabfa2ee478ce5d86df4210a16c5370fa7d0ebeeb9f8f2a9ca8690ded8f31fb4ccfac8432682fcde8531c0d3b9874fe5f3941e3f142aa9cb6aa6
6
+ metadata.gz: 085b886ec7d5caa80d38022e7dcc158d0983c5f30008ec5f123da796ac7fe962ef829a5575f2f37e9e5732e091ba122a52474920930f2de37425d7cdb3d89198
7
+ data.tar.gz: d721a5062a1b0b335da3a68fe087ba050c11407bf0a298fcd9ccc1b3cce66ceff74546e787af4c1c2d2a5569f44a2a14a3c297bd56b94465203e8c4908e9fe31
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /doc/
7
7
  /pkg/
8
8
  /spec/reports/
9
+ /spec/dummy/log/*
9
10
  /tmp/
10
11
  *.bundle
11
12
  *.so
@@ -2,16 +2,16 @@ require 'rails/engine'
2
2
 
3
3
  module DbCharmerEnvUrls
4
4
  class Engine < ::Rails::Engine
5
+ # Merges any database urls from the ENV into the current environment's configurations
6
+ #
7
+ # @see https://github.com/rails/rails/blob/38af3540ae53b9f2fbdb649a68cde3edf182fe67/activerecord/lib/active_record/railtie.rb#L79 ActiveRecord's default initializer
8
+ # @see DbCharmerEnvUrls.database_configurations
5
9
  initializer "database_urls.initialize_database", after: "active_record.initialize_database" do
6
10
  ActiveSupport.on_load(:active_record) do
7
- B = ActiveRecord::Base
8
- ENV.each do |key, url|
9
- if matches = key.match(/\A(\w+)_DATABASE_URL\z/)
10
- config = B::ConnectionSpecification::Resolver.new(url, B.configurations).spec.config
11
- B.configurations[Rails.env] ||= {}
12
- B.configurations[Rails.env][matches[1].downcase] = config.stringify_keys
13
- end
14
- end
11
+ base = ActiveRecord::Base
12
+ # This will not be set if DATABASE_URL isn't used
13
+ base.configurations[Rails.env] ||= {}
14
+ base.configurations[Rails.env].merge!(DbCharmerEnvUrls.database_configurations)
15
15
  end
16
16
  end
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module DbCharmerEnvUrls
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -2,4 +2,32 @@ require "db_charmer_env_urls/engine"
2
2
  require "db_charmer_env_urls/version"
3
3
 
4
4
  module DbCharmerEnvUrls
5
+ # Extracts database configs from the ENV where ENV key ends it _DATABASE_URL
6
+ #
7
+ # @example Matching ENV variable names
8
+ # SLAVE_DATABASE_URL, CRIMSON_DATABASE_URL
9
+ #
10
+ # @example Usage
11
+ # ENV["SLAVE_DATABASE_URL"] = "postgres://localhost:5432/name"
12
+ # DbCharmerEnvUrls.database_configurations
13
+ # {
14
+ # "slave" => {
15
+ # "adapter" => "postgres",
16
+ # "host" => "localhost",
17
+ # "port" => 5432,
18
+ # "database" => "name"
19
+ # }
20
+ # }
21
+ #
22
+ # @return [Hash] Hash of database configurations whose keys are extracted from the ENV and whose values are hashes of database configs
23
+ def self.database_configurations
24
+ base = ActiveRecord::Base
25
+ ENV.inject({}) do |acc, (key, url)|
26
+ if matches = key.match(/\A(\w+)_DATABASE_URL\z/)
27
+ config = base::ConnectionSpecification::Resolver.new(url, base.configurations).spec.config
28
+ acc[matches[1].downcase] = config.stringify_keys
29
+ end
30
+ acc
31
+ end
32
+ end
5
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_charmer_env_urls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Hahn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-05 00:00:00.000000000 Z
11
+ date: 2014-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -171,8 +171,6 @@ files:
171
171
  - spec/dummy/dummy/script/rails
172
172
  - spec/dummy/lib/assets/.gitkeep
173
173
  - spec/dummy/log/.gitkeep
174
- - spec/dummy/log/development.log
175
- - spec/dummy/log/test.log
176
174
  - spec/dummy/public/404.html
177
175
  - spec/dummy/public/422.html
178
176
  - spec/dummy/public/500.html
@@ -264,8 +262,6 @@ test_files:
264
262
  - spec/dummy/dummy/script/rails
265
263
  - spec/dummy/lib/assets/.gitkeep
266
264
  - spec/dummy/log/.gitkeep
267
- - spec/dummy/log/development.log
268
- - spec/dummy/log/test.log
269
265
  - spec/dummy/public/404.html
270
266
  - spec/dummy/public/422.html
271
267
  - spec/dummy/public/500.html
@@ -1,7 +0,0 @@
1
- Connecting to database specified by database.yml
2
- Connecting to database specified by database.yml
3
- Connecting to database specified by database.yml
4
- Connecting to database specified by database.yml
5
- Connecting to database specified by database.yml
6
- Connecting to database specified by database.yml
7
- Connecting to database specified by database.yml
@@ -1,27 +0,0 @@
1
- Connecting to database specified by database.yml
2
- Connecting to database specified by database.yml
3
- Connecting to database specified by database.yml
4
- Connecting to database specified by database.yml
5
- Connecting to database specified by database.yml
6
- Connecting to database specified by database.yml
7
- Connecting to database specified by database.yml
8
- Connecting to database specified by database.yml
9
- Connecting to database specified by database.yml
10
- Connecting to database specified by database.yml
11
- Connecting to database specified by database.yml
12
- Connecting to database specified by database.yml
13
- Connecting to database specified by database.yml
14
- Connecting to database specified by database.yml
15
- Connecting to database specified by database.yml
16
- Connecting to database specified by database.yml
17
- Connecting to database specified by database.yml
18
- Connecting to database specified by database.yml
19
- Connecting to database specified by database.yml
20
- Connecting to database specified by database.yml
21
- Connecting to database specified by database.yml
22
- Connecting to database specified by database.yml
23
- Connecting to database specified by database.yml
24
- Connecting to database specified by database.yml
25
- Connecting to database specified by database.yml
26
- Connecting to database specified by database.yml
27
- Connecting to database specified by database.yml