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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee4a503703a004e9c25e4741e7703de61c4cb28b
4
- data.tar.gz: 093690ba1c61b1cccefc46aeab9fa3762a2b13d9
3
+ metadata.gz: ffb497917171ccf1cb97c0f37a4bd87462fc6557
4
+ data.tar.gz: 97d68fa4666773b80d0e5de86c3f0e227739fd08
5
5
  SHA512:
6
- metadata.gz: ec2bdc27e3a13eebc34c51f587563ed2e78d030504f98000f8ac69805a74d442e0e0c9284e5af3c920c8707ca664b7d797ab631013cba6ec670f6aeb48c5adc7
7
- data.tar.gz: c9eb2f9b4cced192906de26f28e569320db289eb6b193a0135d195fb3c1139e649518fca7372d3fb536c03f74cfd2893e40ecf2fd040c1018607036ce0ac6083
6
+ metadata.gz: 02bbfaf0368fba000643e041b2b4259e7f42fac18b6fa021e89bf4f2b95ead984c3f7a09dc64e71a4eb6fd3370045bdd5ee5a5cc6c46107a6155c91cb3ce6ce5
7
+ data.tar.gz: 9f4ab4e4e8a458a8f49c1f3e40bcd34eabdb1b8f343dbc1ca0322c8dd0286e19f356049a4193164235cd7d99b7214698108f5890a2b5c416f6a27210da80afcb
@@ -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
- yield self.config if block_given?
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(cfg)
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.before_initialize do
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
- # initialize the module before db:load_config task so that app config is available for all 'db' tasks
9
- Rake::Task['db:load_config'].enhance %w(app_config_loader:init)
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
@@ -1,3 +1,3 @@
1
1
  module AppConfigLoader
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.6'
3
3
  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
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: 2017-04-29 00:00:00.000000000 Z
11
+ date: 2018-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler