stacked_config 0.0.2 → 0.1.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: a704406dfd46dd2f353d6aaa5dce2dee1608c257
4
- data.tar.gz: fc274646518d279ba4f81578ab180f0b23aed082
3
+ metadata.gz: 0cc8ac49474011f38a0cf1b6859849c9feb356b9
4
+ data.tar.gz: 5b5076b0f63330df95152b0403619043807bee21
5
5
  SHA512:
6
- metadata.gz: 855ba677dcfd1ff998845225a19cfa022dbb50065b1e5498333d499edbe74c6350c246f0e66bb926225982d9cdc9e12de59b16f5b1cde631a4749206f792c5b5
7
- data.tar.gz: e6da7ea0fbf7a30f459f47057a0fa5097779502df96f61938e5800e4c305d9181573eed91d12e4082c5e365c0cf198761c50370dccac2ef055defeed76060ab6
6
+ metadata.gz: f66b20e0469a6c5f3ce095c401ec1ba527ef9e9a0e1a15e597c02d6d4b4f7ddf7d90362548fe9b757b9e4b2822a94bb321f463181ecd375e92f2735fa0b2a16c
7
+ data.tar.gz: 4f6b134a3dc729a0a03f67c70338eac58cae74780df30ee62d90a822bd5bb7026966cd1cec9fba06105b9f402c52d856f34d4f7f302a46c63bd1350734102359
data/.gitignore CHANGED
@@ -1,8 +1,9 @@
1
1
  *.gem
2
2
  *.rbc
3
3
  .bundle
4
- .config
4
+ /.config
5
5
  .yardoc
6
+ .idea
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
@@ -9,5 +9,6 @@ require 'stacked_config/layers/system_layer'
9
9
  require 'stacked_config/layers/global_layer'
10
10
  require 'stacked_config/layers/user_layer'
11
11
  require 'stacked_config/layers/command_line_layer'
12
+ require 'stacked_config/layers/provided_config_file_layer'
12
13
  require 'stacked_config/orchestrator'
13
14
 
@@ -0,0 +1,31 @@
1
+ module StackedConfig
2
+ module Layers
3
+
4
+ class ProvidedConfigFileLayer < SuperStack::Layer
5
+
6
+
7
+ def managed
8
+ build_command_line_options unless @already_built
9
+ if manager[:'config-file']
10
+ if File.readable? manager[:'config-file']
11
+ @file_name = manager[:'config-file']
12
+ self.merge_policy = SuperStack::MergePolicies::OverridePolicy if manager[:'config-override']
13
+ end
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def build_command_line_options
20
+ manager.add_command_line_section('Configuration options') do |slop|
21
+ slop.on 'config-file', 'Specify a config file.', :argument => true
22
+ slop.on 'config-override', 'If specified override all other config.', :argument => false
23
+ end
24
+ @already_built = true
25
+ end
26
+
27
+
28
+ end
29
+
30
+ end
31
+ end
@@ -3,7 +3,8 @@ module StackedConfig
3
3
 
4
4
  include StackedConfig::ProgramDescriptionHelper
5
5
 
6
- attr_reader :system_layer, :global_layer, :user_layer, :command_line_layer
6
+ attr_reader :system_layer, :global_layer, :user_layer, :command_line_layer,
7
+ :provided_config_file_layer
7
8
 
8
9
  def initialize
9
10
  super
@@ -16,6 +17,10 @@ module StackedConfig
16
17
  private
17
18
 
18
19
  def setup_layers
20
+
21
+ # The command line level.
22
+ @command_line_layer = setup_layer StackedConfig::Layers::CommandLineLayer, 'Command line configuration level', 100
23
+
19
24
  # The system level
20
25
  @system_layer = setup_layer StackedConfig::Layers::SystemLayer, 'System-wide configuration level', 10
21
26
 
@@ -25,8 +30,8 @@ module StackedConfig
25
30
  # The user level
26
31
  @user_layer = setup_layer StackedConfig::Layers::UserLayer, 'User configuration level', 30
27
32
 
28
- # The command line level
29
- @command_line_layer = setup_layer StackedConfig::Layers::CommandLineLayer, 'Command line configuration level', 100
33
+ # The specifically provided config file level
34
+ @provided_config_file_layer = setup_layer StackedConfig::Layers::ProvidedConfigFileLayer, 'Specific config file configuration level', 40
30
35
 
31
36
  # The layer to write something
32
37
  override_layer = setup_layer SuperStack::Layer, 'Overridden configuration level', 1000
@@ -1,3 +1,3 @@
1
1
  module StackedConfig
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -30,10 +30,10 @@ describe StackedConfig::Orchestrator do
30
30
  context 'when changing the executable_name' do
31
31
 
32
32
  it 'should reload all config files' do
33
- expect(subject[:user_defined]).not_to be_nil
33
+ expect(subject[:user_property]).not_to be_nil
34
34
  expect(subject[:weird_property]).to be_nil
35
35
  subject.executable_name = 'weird_name'
36
- expect(subject[:user_defined]).to be_nil
36
+ expect(subject[:user_property]).to be_nil
37
37
  expect(subject[:weird_property]).not_to be_nil
38
38
  end
39
39
 
@@ -59,8 +59,12 @@ describe StackedConfig::Orchestrator do
59
59
  expect(subject.user_layer).to be subject.to_a[2]
60
60
  end
61
61
 
62
- it 'should have the command-line layer evaluated in fourth' do
63
- expect(subject.command_line_layer).to be subject.to_a[3]
62
+ it 'should have the specific-file layer evaluated in fourth' do
63
+ expect(subject.provided_config_file_layer).to be subject.to_a[3]
64
+ end
65
+
66
+ it 'should have the command-line layer evaluated in fifth' do
67
+ expect(subject.command_line_layer).to be subject.to_a[4]
64
68
  end
65
69
 
66
70
  it 'should have the writable layer evaluated last' do
@@ -69,7 +73,42 @@ describe StackedConfig::Orchestrator do
69
73
 
70
74
  end
71
75
 
76
+ context 'when config-file is provided on the command line' do
77
+
78
+ let(:test_config_file) {
79
+ gem_path = File.expand_path '../..', __FILE__
80
+ File.join gem_path, 'test', 'specific.yml'
81
+ }
82
+
83
+ it 'should add the content of the specified config-file' do
84
+ subject[:'config-file'] = test_config_file
85
+ subject.provided_config_file_layer.managed
86
+ subject.provided_config_file_layer.reload
87
+ expect(subject[:system_property]).not_to be_nil
88
+ expect(subject[:global_property]).not_to be_nil
89
+ expect(subject[:user_property]).not_to be_nil
90
+ expect(subject[:specific_property]).not_to be_nil
91
+ end
92
+
93
+
94
+ context 'when specifying config-override on the command line' do
72
95
 
96
+ it 'should override all preceding layers (system, global, user)' do
97
+ subject[:'config-file'] = test_config_file
98
+ subject[:'config-override'] = true
99
+ subject.provided_config_file_layer.managed
100
+ subject.provided_config_file_layer.reload
101
+ expect(subject[:system_property]).to be_nil
102
+ expect(subject[:global_property]).to be_nil
103
+ expect(subject[:user_property]).to be_nil
104
+ expect(subject[:specific_property]).not_to be_nil
105
+ expect(subject[:'config-override']).not_to be_nil
106
+ end
107
+
108
+
109
+ end
110
+
111
+ end
73
112
 
74
113
 
75
114
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe StackedConfig::Layers::ProvidedConfigFileLayer do
5
+
6
+ subject { StackedConfig::Layers::ProvidedConfigFileLayer.new }
7
+
8
+
9
+ it 'should be empty by default' do
10
+ expect(subject.empty?).to be_truthy
11
+ end
12
+
13
+
14
+
15
+ end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'pry'
24
24
  spec.add_development_dependency 'rspec', '~> 3.0'
25
25
 
26
- spec.add_dependency 'super_stack', '~> 0.2', '>= 0.2.3'
26
+ spec.add_dependency 'super_stack', '~> 0.2', '>= 0.2.4'
27
27
  spec.add_dependency 'slop'
28
28
 
29
29
  end
data/test/specific.yml ADDED
@@ -0,0 +1,6 @@
1
+ # This is supposed to be a file loaded using the config-file command line option.
2
+ # It is dedicated to configuration for this particular user running the program.
3
+
4
+ specific_property: foo
5
+ an_array:
6
+ - something very specific
@@ -2,6 +2,7 @@
2
2
  # It is dedicated to configuration for all users running the program rspec
3
3
  # To be used at administrator level only
4
4
 
5
+ global_property: foo
5
6
  an_array:
6
7
  - defined at global level
7
8
  - pretty cool (global)
@@ -2,4 +2,5 @@
2
2
  # It is dedicated to configuration for all gems that would use the stacked_config gem.
3
3
  # To be used at administrator level only
4
4
 
5
- stacked_config_copyright: (c)2014 L.Briais under MIT license
5
+ stacked_config_copyright: (c)2014 L.Briais under MIT license
6
+ system_property: foo
@@ -0,0 +1,7 @@
1
+ # This is supposed to be a file at "user" level.
2
+ # It is dedicated to configuration for this particular user running the program rspec.
3
+ # To be used at user level
4
+
5
+ user_property: foo
6
+ an_array:
7
+ - something weird (at user level)
@@ -0,0 +1,5 @@
1
+ # This is supposed to be a file at "user" level.
2
+ # It is dedicated to configuration for this particular user running the program rspec.
3
+ # To be used at user level
4
+
5
+ weird_property: Defined in 'weird_name' config file.
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.0.2
4
+ version: 0.1.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-21 00:00:00.000000000 Z
11
+ date: 2014-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,7 +75,7 @@ dependencies:
75
75
  version: '0.2'
76
76
  - - '>='
77
77
  - !ruby/object:Gem::Version
78
- version: 0.2.3
78
+ version: 0.2.4
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -85,7 +85,7 @@ dependencies:
85
85
  version: '0.2'
86
86
  - - '>='
87
87
  - !ruby/object:Gem::Version
88
- version: 0.2.3
88
+ version: 0.2.4
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: slop
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -117,6 +117,7 @@ files:
117
117
  - lib/stacked_config/layers/command_line_layer.rb
118
118
  - lib/stacked_config/layers/generic_layer.rb
119
119
  - lib/stacked_config/layers/global_layer.rb
120
+ - lib/stacked_config/layers/provided_config_file_layer.rb
120
121
  - lib/stacked_config/layers/system_layer.rb
121
122
  - lib/stacked_config/layers/user_layer.rb
122
123
  - lib/stacked_config/orchestrator.rb
@@ -126,13 +127,17 @@ files:
126
127
  - spec/command_line_layer_spec.rb
127
128
  - spec/global_layer_spec.rb
128
129
  - spec/orchestrator_spec.rb
130
+ - spec/provided_config_file_layer_spec.rb
129
131
  - spec/source_helper_spec.rb
130
132
  - spec/spec_helper.rb
131
133
  - spec/system_layer_spec.rb
132
134
  - spec/user_layer_spec.rb
133
135
  - stacked_config.gemspec
136
+ - test/specific.yml
134
137
  - test/unix/etc/rspec/rspec.yml
135
138
  - test/unix/etc/stacked_config.yml
139
+ - test/user/.config/rspec.yml
140
+ - test/user/.config/weird_name.yml
136
141
  homepage: https://github.com/lbriais/stacked_config
137
142
  licenses:
138
143
  - MIT
@@ -161,9 +166,13 @@ test_files:
161
166
  - spec/command_line_layer_spec.rb
162
167
  - spec/global_layer_spec.rb
163
168
  - spec/orchestrator_spec.rb
169
+ - spec/provided_config_file_layer_spec.rb
164
170
  - spec/source_helper_spec.rb
165
171
  - spec/spec_helper.rb
166
172
  - spec/system_layer_spec.rb
167
173
  - spec/user_layer_spec.rb
174
+ - test/specific.yml
168
175
  - test/unix/etc/rspec/rspec.yml
169
176
  - test/unix/etc/stacked_config.yml
177
+ - test/user/.config/rspec.yml
178
+ - test/user/.config/weird_name.yml