app_config_loader 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/app_config_loader.rb +15 -3
- data/lib/app_config_loader/railtie.rb +1 -1
- data/lib/app_config_loader/tasks.rake +4 -2
- data/lib/app_config_loader/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffb497917171ccf1cb97c0f37a4bd87462fc6557
|
4
|
+
data.tar.gz: 97d68fa4666773b80d0e5de86c3f0e227739fd08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02bbfaf0368fba000643e041b2b4259e7f42fac18b6fa021e89bf4f2b95ead984c3f7a09dc64e71a4eb6fd3370045bdd5ee5a5cc6c46107a6155c91cb3ce6ce5
|
7
|
+
data.tar.gz: 9f4ab4e4e8a458a8f49c1f3e40bcd34eabdb1b8f343dbc1ca0322c8dd0286e19f356049a4193164235cd7d99b7214698108f5890a2b5c416f6a27210da80afcb
|
data/lib/app_config_loader.rb
CHANGED
@@ -9,8 +9,12 @@ require 'app_config_loader/config_with_indifferent_access'
|
|
9
9
|
require 'app_config_loader/railtie' if defined?(Rails)
|
10
10
|
|
11
11
|
module AppConfigLoader
|
12
|
+
@cfg_blocks = []
|
13
|
+
|
12
14
|
# Configure the module
|
13
15
|
#
|
16
|
+
# The block will be executed at during ::init
|
17
|
+
#
|
14
18
|
# @yield [config] configuration block
|
15
19
|
# @yieldparam [AppConfigLoader::Config] config the config object
|
16
20
|
#
|
@@ -20,8 +24,8 @@ module AppConfigLoader
|
|
20
24
|
# config.domain = 'us'
|
21
25
|
# config.config_paths << '/path/to/app_config.yml'
|
22
26
|
# end
|
23
|
-
def self.configure
|
24
|
-
|
27
|
+
def self.configure(&block)
|
28
|
+
@cfg_blocks << block if block_given?
|
25
29
|
end
|
26
30
|
|
27
31
|
# Initialize the module
|
@@ -29,10 +33,11 @@ module AppConfigLoader
|
|
29
33
|
#
|
30
34
|
# @raise [NameError] the constant has already been defined
|
31
35
|
def self.init
|
36
|
+
self.run_config_blocks
|
32
37
|
cfg = self.config
|
33
38
|
|
34
39
|
raise NameError, "cannot assign app config because '#{cfg.const_name}' is already defined" if Object.const_defined?(cfg.const_name)
|
35
|
-
Object.const_set cfg.const_name, self.load(
|
40
|
+
Object.const_set cfg.const_name, self.load(self.config)
|
36
41
|
|
37
42
|
@inited = true
|
38
43
|
end
|
@@ -67,6 +72,13 @@ module AppConfigLoader
|
|
67
72
|
|
68
73
|
private
|
69
74
|
|
75
|
+
def self.run_config_blocks
|
76
|
+
@config = @cfg_blocks.reduce(self.config) do |cfg, cfg_block|
|
77
|
+
cfg_block.call cfg
|
78
|
+
cfg
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
70
82
|
def self.config
|
71
83
|
@config ||= self.default_config
|
72
84
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module AppConfigLoader
|
2
2
|
class Railtie < Rails::Railtie
|
3
|
-
config.
|
3
|
+
config.before_configuration do
|
4
4
|
# initialize the app config before Rails initialization unless it has already been initialized
|
5
5
|
AppConfigLoader.init unless AppConfigLoader.initialized?
|
6
6
|
end
|
@@ -5,5 +5,7 @@ namespace :app_config_loader do
|
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
if Rake::Task.task_defined? 'db:load_config'
|
9
|
+
# initialize the module before db:load_config task so that app config is available for all 'db' tasks
|
10
|
+
Rake::Task['db:load_config'].enhance %w(app_config_loader:init)
|
11
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_config_loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derrick Yeung
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|