app_config_loader 1.0.3 → 1.0.4

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: 1e592723d0d4dc4f9f4640900c9898bb83fd4c35
4
- data.tar.gz: c2b0ffc59d4e620846cab0c9f38a245e34460ec7
3
+ metadata.gz: ee4a503703a004e9c25e4741e7703de61c4cb28b
4
+ data.tar.gz: 093690ba1c61b1cccefc46aeab9fa3762a2b13d9
5
5
  SHA512:
6
- metadata.gz: 8478ba6318c4ff97a6c47f8e04358d26086f07f88db2e2a5fc00b69f96aada7fadf6d391d97a6aa84ea1dfe6eefb2eb2dcc9561bedd9caed34f3f2070fff2db9
7
- data.tar.gz: 528e97b31426dd3aa76a782a0d19945763c826c5d861e1015bd053bc25460b019e7f26ac6c21cfede5a839fa188d865c3eba223758c7f111ac3a74f25ef548f8
6
+ metadata.gz: ec2bdc27e3a13eebc34c51f587563ed2e78d030504f98000f8ac69805a74d442e0e0c9284e5af3c920c8707ca664b7d797ab631013cba6ec670f6aeb48c5adc7
7
+ data.tar.gz: c9eb2f9b4cced192906de26f28e569320db289eb6b193a0135d195fb3c1139e649518fca7372d3fb536c03f74cfd2893e40ecf2fd040c1018607036ce0ac6083
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## [v1.0.4](https://github.com/lscspirit/app_config_loader/tree/v1.0.4) (2017-04-30)
4
+ [Full list of commits](https://github.com/lscspirit/app_config_loader/compare/v1.0.3...v1.0.4)
5
+
6
+ - Auto-initialize in Rails 'db' tasks
7
+
3
8
  ## [v1.0.3](https://github.com/lscspirit/app_config_loader/tree/v1.0.3) (2017-04-23)
4
9
  [Full list of commits](https://github.com/lscspirit/app_config_loader/compare/v1.0.2...v1.0.3)
5
10
 
data/README.md CHANGED
@@ -46,7 +46,10 @@ When using `AppConfigLoader` outside of Rails, getting started is a little diffe
46
46
 
47
47
  ## Configuration
48
48
 
49
- You can configure where and how AppConfigLoader load your app config file(s).
49
+ You can configure where and how AppConfigLoader load your app config file(s).
50
+
51
+ In Rails, the following code should be placed
52
+ before Rails is initialized but after your Rails application is defined (e.g. `config/application.rb`). Outside Rails, this should be placed before the `AppConfigLoader.init` call.
50
53
 
51
54
  ```ruby
52
55
  AppConfigLoader.configure do |config|
@@ -220,6 +223,21 @@ conflict with each other and a `ConfigKeyConflict` error will be raises.
220
223
 
221
224
  The local overrides file provides a quick way to override any entries defined in regular app config files. Entries within this file are resolved according to the specificity rule. Once resolved, the resolved entries will override any existing entries regardless of specificity. This is meant for development or testing purposes. Typically, you would not want to check this file into your source repository.
222
225
 
226
+ ## Manual Load
227
+
228
+ Apart from initializing the module using `AppConfigLoader.init`, you may also manually parse and load app config.
229
+
230
+ ```ruby
231
+ config = AppConfigLoader::Config.new
232
+ config.use_domain = true
233
+ config.env = 'development'
234
+ config.config_paths << '/path/to/app_config.yml'
235
+
236
+ app_config = AppConfigLoader::load(config)
237
+ app_config['some_config.key'] #=> config value for the 'some_config.key' key
238
+
239
+ ```
240
+
223
241
  ## Contributors
224
242
 
225
243
  Bug reports and pull requests are welcome on GitHub at https://github.com/lscspirit/app_config_loader. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
@@ -9,21 +9,57 @@ 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
+ # Configure the module
12
13
  #
13
- # Config
14
+ # @yield [config] configuration block
15
+ # @yieldparam [AppConfigLoader::Config] config the config object
14
16
  #
15
-
17
+ # @example Change the default settings
18
+ # AppConfigLoader.configure do |config|
19
+ # config.use_domain = true
20
+ # config.domain = 'us'
21
+ # config.config_paths << '/path/to/app_config.yml'
22
+ # end
16
23
  def self.configure
17
24
  yield self.config if block_given?
18
25
  end
19
26
 
27
+ # Initialize the module
28
+ # This parse and load the app config into the constant specified by the configuration's +const_name+ property
29
+ #
30
+ # @raise [NameError] the constant has already been defined
20
31
  def self.init
21
32
  cfg = self.config
22
33
 
23
34
  raise NameError, "cannot assign app config because '#{cfg.const_name}' is already defined" if Object.const_defined?(cfg.const_name)
24
35
  Object.const_set cfg.const_name, self.load(cfg)
36
+
37
+ @inited = true
38
+ end
39
+
40
+ # Whether the module has been initialized
41
+ #
42
+ # @return [Boolean] the module is initialized
43
+ def self.initialized?
44
+ !!@inited
25
45
  end
26
46
 
47
+ # Parse and load the app config
48
+ #
49
+ # @param [AppConfigLoader::Config] config configuration to use when loading the app config
50
+ #
51
+ # @raise [ArgumentError] configuration is invalid
52
+ #
53
+ # @return [AppConfigLoader::ConfigWithIndifferentAccess] app config map
54
+ #
55
+ # @example Manually load app config
56
+ # config = AppConfigLoader::Config.new
57
+ # config.use_domain = true
58
+ # config.env = 'development'
59
+ # config.config_paths << '/path/to/app_config.yml'
60
+ #
61
+ # app_config = AppConfigLoader::load(config)
62
+ # app_config['some_config.key'] #=> config value for the 'some_config.key' key
27
63
  def self.load(config = nil)
28
64
  raise ArgumentError, 'config must be a AppConfigLoader::Config instance' unless config.nil? || config.is_a?(AppConfigLoader::Config)
29
65
  Loader.new(config || self.config).load
@@ -7,6 +7,15 @@ module AppConfigLoader
7
7
  @prefix = prefix
8
8
  end
9
9
 
10
+ # Get value for a specified config key
11
+ #
12
+ # @param [String] key app config key
13
+ #
14
+ # @return the value for the key or another ConfigWithIndifferentAccess; nil if there is no value at the key
15
+ #
16
+ # @example Getting key value
17
+ # app_config['some_service.host'] # => 'dev.someservice.com'
18
+ # app_config.get('some_service.host') # => 'dev.someservice.com'
10
19
  def get(key)
11
20
  # append prefix to the key if needed
12
21
  target_key = @prefix ? "#{@prefix}.#{key}" : key.to_s
@@ -1,8 +1,13 @@
1
1
  module AppConfigLoader
2
2
  class Railtie < Rails::Railtie
3
3
  config.before_initialize do
4
- # initialize the app config before Rails initialization
5
- AppConfigLoader.init
4
+ # initialize the app config before Rails initialization unless it has already been initialized
5
+ AppConfigLoader.init unless AppConfigLoader.initialized?
6
+ end
7
+
8
+ rake_tasks do
9
+ # install a rake task for initializing the module
10
+ load File.expand_path('../tasks.rake', __FILE__)
6
11
  end
7
12
  end
8
13
  end
@@ -0,0 +1,9 @@
1
+ namespace :app_config_loader do
2
+ task :init do
3
+ # initialize AppConfigLoader unless it has already been done so
4
+ AppConfigLoader.init unless AppConfigLoader.initialized?
5
+ end
6
+ end
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)
@@ -1,3 +1,3 @@
1
1
  module AppConfigLoader
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
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.3
4
+ version: 1.0.4
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-23 00:00:00.000000000 Z
11
+ date: 2017-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,6 +91,7 @@ files:
91
91
  - lib/app_config_loader/loader.rb
92
92
  - lib/app_config_loader/parser.rb
93
93
  - lib/app_config_loader/railtie.rb
94
+ - lib/app_config_loader/tasks.rake
94
95
  - lib/app_config_loader/version.rb
95
96
  homepage: https://github.com/lscspirit/app_config_loader
96
97
  licenses: