stacked_config 0.2.1 → 0.3.0

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: e02ee146b2273b5918c9d33767b310694cebfed8
4
- data.tar.gz: e4276b0fcbe9f34bd216b0a05afda2f6ad628d2f
3
+ metadata.gz: 1cfebc92ab8edbb67a0c07dda951492e63887963
4
+ data.tar.gz: c6de809414f4bf51c35d755a602cc6619eb5d490
5
5
  SHA512:
6
- metadata.gz: 22af861beccd0d705a80e6c14642a0ed27f060dc3455fabe9249c0558052525ca6382e85b0338e6d4cb47af1d9698a48f96826c0a8e4f678c32db622499b7e2b
7
- data.tar.gz: e6b35a76082840de8bb137a81ed4bbad1f45c37018b2d676e2d022c5cebabac823613434780e2410a501007e5c891f7400be1856f98e623027646115e20bca31
6
+ metadata.gz: 55be0be98df85a6f2a26a909282b9d6fbc08cd33f3baca77ade22bc08db01a51a58867b095329f00e06300352c4919ecc137f24377051f9abb754b1d74b3424e
7
+ data.tar.gz: 96c6f431ee050279f78fba963defcc707f52b05fa2d5b94141018791a61a6eda84d84ec1ec1e6fa0d8e833c287115da6d2bc2a96aae8abc12d4ca7b030ef87f2
data/README.md CHANGED
@@ -9,11 +9,12 @@ running the application, some coming from the command line and more, __[This Gem
9
9
  The purpose of this gem is to provide a __simple__ way to handle the __inheritance__ of __config files__ for a ruby
10
10
  script. By default, it will handle already few config layers:
11
11
 
12
- * The __system layer__, which is a level common to all applications using this gem.
13
- * The __gem layer__, which is the layer that will enable a gem to embed its own config.
14
- * The __global layer__, which is the level to declare options for all users that use the ruby script using this gem.
15
- * The __user layer__, which is the level, where a user can set options for the ruby script using this gem.
16
- * The __extra layer__, which provides the possibility to specify another config file from the command line.
12
+ * The __system layer__, which is a layer common to all applications using this gem.
13
+ * The __gem layer__, which is the layer that will enable a gem to embed its own config. __You may consider this level
14
+ as the layer where you will set the default values for your properties__.
15
+ * The __global layer__, which is the layer to declare options for all users that use the ruby script using this gem.
16
+ * The __user layer__, which is the layer, where a user can set options for the ruby script using this gem.
17
+ * The __extra layer__, which provides the possibility to specify another config file from the config itself.
17
18
  * The __command-line layer__, which provides the ability to specify options from the command line.
18
19
  * The __override layer__, which will contain all modifications done to the config at run time.
19
20
 
@@ -22,8 +23,8 @@ detail). The `StackedConfig::Orchestrator` will expose a merged view of all its
22
23
 
23
24
  All the config files are following the [YAML] syntax.
24
25
 
25
- __If you're looking for a complete solution for your scripts, including some logging features, then you are probably
26
- looking for the [easy_app_helper Gem][EAH], which is internally using [this one][SC].__
26
+ __If you're looking for a complete solution for your command line scripts, including some logging features, then you
27
+ are probably looking for the [easy_app_helper Gem][EAH], which is itself internally relying on [stacked_config][SC].__
27
28
 
28
29
  ## Installation
29
30
 
@@ -101,7 +102,7 @@ As you can see in the sources, paths are expressed using kind of 'templates', wh
101
102
  * `##GEM_CONFIG_ROOT##` is the path to the "current" Gem root. The current gem being the one containing the
102
103
  currently executing script.
103
104
  * `##PROGRAM_NAME##` is by default the name of the script you are running (with no extension). You can if you want
104
- change this name at runtime. __Changing it (using the `executable_name` orchestrator property ) will trigger a
105
+ change this name at runtime. __Changing it (using the `config_file_base_name` orchestrator property ) will trigger a
105
106
  re-search and reload of all the config files__.
106
107
  * `##EXTENSION##` is one of the following extensions : `conf CONF cfg CFG yml YML yaml YAML`.
107
108
 
@@ -122,6 +123,8 @@ user config level, only the first is taken in account:
122
123
  `stacked_config` uses internally the fantastic [Slop] gem to manage options coming from the command line within the
123
124
  command line layer. This layer will be simply part of the complete config that the orchestrator exposes.
124
125
 
126
+ `stacked_config` is using the v3 branch of [Slop] and has not yet been adapted to the newest v4 branch.
127
+
125
128
  #### Command line help
126
129
 
127
130
  You can easily display a help using the orchestrator `command_line_help` method.
@@ -226,6 +229,7 @@ end
226
229
  ```
227
230
 
228
231
  The `add_command_line_section` method supports a parameter to define the name of the section.
232
+ Check [Slop] documentation for further information.
229
233
 
230
234
  __Of course adding new command line options will adapt the display of the `command_line_help` method of the
231
235
  orchestrator__.
@@ -233,6 +237,9 @@ orchestrator__.
233
237
 
234
238
  ## Advanced usage
235
239
 
240
+ `stacked_config` is internally relying on the [super_stack Gem][SS] for the management of the layers, their priorities
241
+ and the way they are merged in order to provide the "merged config". Check its documentation for further info.
242
+
236
243
  ### Re-ordering layers
237
244
 
238
245
  The way layers are processed is done according to their priority. By default the existing layers have the following
@@ -264,7 +271,7 @@ in those files cannot be overridden even at command line level thanks to [super_
264
271
  ### Adding extra layers
265
272
 
266
273
  Imagine you want to add a specific layer in your config, coming from let's say a web-service or a database, you may
267
- create your own layers for this purpose. Have a look at [super_stack gem][SS] for further info about how to create
274
+ create your own layers for this purpose. Have a look at [super_stack Gem][SS] for further info about how to create
268
275
  layers.
269
276
 
270
277
  But basically just create your new layer, gives it a priority and add it to the orchestrator.
@@ -13,8 +13,7 @@ module StackedConfig
13
13
  def load(*args)
14
14
  slop_definition.parse
15
15
  slop_definition.banner = build_banner
16
- clear
17
- merge! slop_definition.to_hash.delete_if {|k,v| v.nil?}
16
+ replace slop_definition.to_hash.delete_if {|k,v| v.nil?}
18
17
  end
19
18
 
20
19
  def possible_options
@@ -59,7 +58,7 @@ module StackedConfig
59
58
  if manager.nil?
60
59
  'No banner unless added to a manager !'
61
60
  else
62
- "\nUsage: #{manager.executable_name} [options]\n#{manager.app_name} Version: #{manager.app_version}\n\n#{manager.app_description}"
61
+ "\nUsage: #{manager.config_file_base_name} [options]\n#{manager.app_name} Version: #{manager.app_version}\n\n#{manager.app_description}"
63
62
  end
64
63
  end
65
64
 
@@ -10,12 +10,12 @@ module StackedConfig
10
10
  super
11
11
  self.merge_policy = SuperStack::MergePolicies::FullMergePolicy
12
12
  setup_layers
13
- default_name = self.class.default_executable_name
14
- describes_application executable_name: default_name, app_name: default_name
13
+ default_name = self.class.default_config_file_base_name
14
+ describes_application config_file_base_name: default_name, app_name: default_name
15
15
  end
16
16
 
17
17
 
18
- def self.default_executable_name
18
+ def self.default_config_file_base_name
19
19
  File.basename($PROGRAM_NAME).gsub /\.[^\.]+$/, ''
20
20
  end
21
21
 
@@ -1,15 +1,15 @@
1
1
  module StackedConfig
2
2
  module ProgramDescriptionHelper
3
3
 
4
- attr_reader :executable_name, :app_name, :app_version, :app_description
4
+ attr_reader :config_file_base_name, :app_name, :app_version, :app_description
5
5
 
6
6
  def add_command_line_section(title='Script specific', &block)
7
7
  command_line_layer.add_command_line_section title, &block
8
8
  end
9
9
 
10
- def executable_name=(executable_name)
11
- return if executable_name.nil?
12
- @executable_name = executable_name
10
+ def config_file_base_name=(config_file_base_name)
11
+ return if config_file_base_name.nil?
12
+ @config_file_base_name = config_file_base_name
13
13
  rescan_layers
14
14
  reload_layers
15
15
  end
@@ -72,7 +72,7 @@ module StackedConfig
72
72
  self.app_name = options.fetch(:app_name, nil)
73
73
  self.app_version = options.fetch(:app_version, nil)
74
74
  self.app_description = options.fetch(:app_description, nil)
75
- self.executable_name = options.fetch(:executable_name, nil)
75
+ self.config_file_base_name = options.fetch(:config_file_base_name, nil)
76
76
  end
77
77
 
78
78
  end
@@ -89,7 +89,7 @@ module StackedConfig
89
89
  res.gsub! '##SYSTEM_CONFIG_ROOT##', system_config_root
90
90
  res.gsub! '##USER_CONFIG_ROOT##', user_config_root
91
91
 
92
- exec_name = manager.nil? ? StackedConfig::Orchestrator.default_executable_name : manager.executable_name
92
+ exec_name = manager.nil? ? StackedConfig::Orchestrator.default_config_file_base_name : manager.config_file_base_name
93
93
  res.gsub! '##PROGRAM_NAME##', exec_name
94
94
  if res =~ /##GEM_CONFIG_ROOT##/
95
95
  return nil unless gem_config_root
@@ -1,3 +1,3 @@
1
1
  module StackedConfig
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
 
4
4
  describe StackedConfig::Layers::GemLayer do
5
- # subject is a modified SystemLayer to redirect system_config_root to the test directory
5
+ # subject is a modified SystemLayer to redirect gem_config_root to the test directory
6
6
  subject {
7
7
  s = StackedConfig::Layers::GemLayer.new
8
8
  gem_path = File.expand_path '../..', __FILE__
@@ -29,19 +29,19 @@ describe StackedConfig::Orchestrator do
29
29
  end
30
30
 
31
31
 
32
- context 'when changing the executable_name' do
32
+ context 'when changing the config_file_base_name' do
33
33
 
34
34
  it 'should reload all config files' do
35
35
  expect(subject[:user_property]).not_to be_nil
36
36
  expect(subject[:weird_property]).to be_nil
37
- subject.executable_name = 'weird_name'
37
+ subject.config_file_base_name = 'weird_name'
38
38
  expect(subject[:user_property]).to be_nil
39
39
  expect(subject[:weird_property]).not_to be_nil
40
40
  end
41
41
 
42
42
  it 'should keep the modified values' do
43
43
  subject[:modified_value] = :pipo
44
- subject.executable_name = 'weird_name'
44
+ subject.config_file_base_name = 'weird_name'
45
45
  expect(subject[:modified_value]).not_to be_nil
46
46
  end
47
47
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stacked_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent B.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-31 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler