stacked_config 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 30df24c00c6fc0fcf0d77213239c53de0f782c0d
4
+ data.tar.gz: 8e9862bf7e06e6306cef5ad9967d484cf3585c90
5
+ SHA512:
6
+ metadata.gz: 58aa9225b056d5325d6c3157815f538c4922cd6a36ebdfd9c97f4b94a60c3a829f735a0a38874d3f466a10e82f6c916af5f21bfd0088be23461ac168bf288e9f
7
+ data.tar.gz: 10d8c2e4c8e4749d0420fed026ed30466958ba77fa82bce0f423595806fb9a2d61ffe888028b40871e8bd9d562b2e64a9c8ca789d9a1f8d9e319c1bf4726995a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stacked_config.gemspec
4
+ gemspec
5
+
6
+ # gem 'super_stack', path: '/home/laurent/devel/ruby/gems/super_stack'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Laurent B.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # StackedConfig
2
+
3
+ Code should be ready for prod
4
+
5
+ No doc written for the time being
6
+
7
+ Wait for version 0.1.x
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'stacked_config'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install stacked_config
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( http://github.com/<my-github-username>/stacked_config/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,67 @@
1
+ module StackedConfig
2
+ module Layers
3
+
4
+ class CommandLineLayer < SuperStack::Layer
5
+
6
+ attr_reader :slop_definition
7
+
8
+ def initialize
9
+ @slop_definition = Slop.new
10
+ build_command_line_options
11
+ end
12
+
13
+ def load(*args)
14
+ slop_definition.parse
15
+ slop_definition.banner = build_banner
16
+ clear
17
+ merge! slop_definition.to_hash
18
+ end
19
+
20
+ def reload
21
+ load
22
+ end
23
+
24
+ # Yields a slop definition to modify the command line parameters
25
+ def add_command_line_section(title)
26
+ raise 'Incorrect usage' unless block_given?
27
+ slop_definition.separator build_separator(title)
28
+ yield slop_definition
29
+ reload
30
+ end
31
+
32
+ # @return [String] The formatted command line help
33
+ def help
34
+ slop_definition.to_s
35
+ end
36
+
37
+ private
38
+
39
+ # Builds a nice separator
40
+ def build_separator(title, width = 80, filler = '-')
41
+ "#{filler * 2} #{title} ".ljust width, filler
42
+ end
43
+
44
+ # Builds common used command line options
45
+ def build_command_line_options
46
+ add_command_line_section('Generic options') do |slop|
47
+ slop.on :auto, 'Auto mode. Bypasses questions to user.', :argument => false
48
+ slop.on :simulate, 'Do not perform the actual underlying actions.', :argument => false
49
+ slop.on :v, :verbose, 'Enable verbose mode.', :argument => false
50
+ slop.on :h, :help, 'Displays this help.', :argument => false
51
+ end
52
+ end
53
+
54
+ def build_banner
55
+ if manager.nil?
56
+ 'No banner unless added to a manager !'
57
+ else
58
+ "\nUsage: #{manager.executable_name} [options]\n#{manager.app_name} Version: #{manager.app_version}\n\n#{manager.app_description}"
59
+ end
60
+ end
61
+
62
+
63
+
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,22 @@
1
+ module StackedConfig
2
+ module Layers
3
+
4
+ class GenericLayer < SuperStack::Layer
5
+
6
+ include StackedConfig::SourceHelper
7
+
8
+ attr_reader :orchestrator
9
+
10
+ def rescan
11
+
12
+ set_config_file possible_sources
13
+ end
14
+
15
+ def initialize
16
+ rescan
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module StackedConfig
2
+ module Layers
3
+
4
+ class GlobalLayer < StackedConfig::Layers::GenericLayer
5
+ def possible_sources
6
+ [
7
+ ['##SYSTEM_CONFIG_ROOT##', '##PROGRAM_NAME##.##EXTENSION##' ],
8
+ ['##SYSTEM_CONFIG_ROOT##', '##PROGRAM_NAME##', 'config.##EXTENSION##' ],
9
+ ['##SYSTEM_CONFIG_ROOT##', '##PROGRAM_NAME##', '##PROGRAM_NAME##.##EXTENSION##' ]
10
+ ]
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module StackedConfig
2
+ module Layers
3
+
4
+ class SystemLayer < StackedConfig::Layers::GenericLayer
5
+ def possible_sources
6
+ [
7
+ ['##SYSTEM_CONFIG_ROOT##', 'stacked_config.##EXTENSION##' ],
8
+ ['##SYSTEM_CONFIG_ROOT##', 'stacked_config', 'config.##EXTENSION##' ]
9
+ ]
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module StackedConfig
2
+ module Layers
3
+
4
+ class UserLayer < StackedConfig::Layers::GenericLayer
5
+
6
+ def possible_sources
7
+ [
8
+ ['##USER_CONFIG_ROOT##', '.##PROGRAM_NAME##.##EXTENSION##' ],
9
+ ['##USER_CONFIG_ROOT##', '.config', '##PROGRAM_NAME##.##EXTENSION##' ],
10
+ ['##USER_CONFIG_ROOT##', '.config', '##PROGRAM_NAME##', 'config.##EXTENSION##' ],
11
+ ['##USER_CONFIG_ROOT##', '.config', '##PROGRAM_NAME##', '##PROGRAM_NAME##.##EXTENSION##' ],
12
+ ['##USER_CONFIG_ROOT##', '.##PROGRAM_NAME##', 'config.##EXTENSION##' ],
13
+ ['##USER_CONFIG_ROOT##', '.##PROGRAM_NAME##', '##PROGRAM_NAME##.##EXTENSION##' ]
14
+ ]
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,48 @@
1
+ module StackedConfig
2
+ class Orchestrator < SuperStack::Manager
3
+
4
+ include StackedConfig::ProgramDescriptionHelper
5
+
6
+ attr_reader :system_layer, :global_layer, :user_layer, :command_line_layer
7
+
8
+ def initialize
9
+ super
10
+ self.merge_policy = SuperStack::MergePolicies::FullMergePolicy
11
+ setup_layers
12
+ default_name = File.basename($PROGRAM_NAME)
13
+ describes_application executable_name: default_name, app_name: default_name
14
+ end
15
+
16
+ private
17
+
18
+ def setup_layers
19
+ # The system level
20
+ @system_layer = setup_layer StackedConfig::Layers::SystemLayer, 'System-wide configuration level', 10
21
+
22
+ # The global level
23
+ @global_layer = setup_layer StackedConfig::Layers::GlobalLayer, 'Global configuration level', 20
24
+
25
+ # The user level
26
+ @user_layer = setup_layer StackedConfig::Layers::UserLayer, 'User configuration level', 30
27
+
28
+ # The command line level
29
+ @command_line_layer = setup_layer StackedConfig::Layers::CommandLineLayer, 'Command line configuration level', 100
30
+
31
+ # The layer to write something
32
+ override_layer = setup_layer SuperStack::Layer, 'Overridden configuration level', 1000
33
+ self.write_layer = override_layer
34
+
35
+ reload_layers
36
+ end
37
+
38
+ def setup_layer(class_type, name, priority)
39
+ layer = class_type.new
40
+ layer.name = name
41
+ layer.priority = priority
42
+ self << layer
43
+ layer
44
+ end
45
+
46
+
47
+ end
48
+ end
@@ -0,0 +1,54 @@
1
+ module StackedConfig
2
+ module ProgramDescriptionHelper
3
+
4
+ attr_reader :executable_name, :app_name, :app_version, :app_description
5
+
6
+ def add_command_line_section(title='Script specific', &block)
7
+ command_line_layer.add_command_line_section title, &block
8
+ end
9
+
10
+ def executable_name=(executable_name)
11
+ return if executable_name.nil?
12
+ @executable_name = executable_name
13
+ rescan_layers
14
+ reload_layers
15
+ end
16
+
17
+ def app_name=(app_name)
18
+ return if app_name.nil?
19
+ @app_name = app_name
20
+ command_line_layer.reload
21
+ end
22
+
23
+ def app_version=(app_version)
24
+ return if app_version.nil?
25
+ @app_version = app_version
26
+ command_line_layer.reload
27
+ end
28
+
29
+ def app_description=(app_description)
30
+ return if app_description.nil?
31
+ @app_description = app_description
32
+ command_line_layer.reload
33
+ end
34
+
35
+ def rescan_layers
36
+ layers.values.each do |layer|
37
+ if layer.respond_to? :rescan
38
+ layer.clear
39
+ layer.rescan
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ def describes_application(options = {})
46
+ self.app_name = options.fetch(:app_name, nil)
47
+ self.app_version = options.fetch(:app_version, nil)
48
+ self.app_description = options.fetch(:app_description, nil)
49
+ self.executable_name = options.fetch(:executable_name, nil)
50
+ end
51
+
52
+ end
53
+ end
54
+
@@ -0,0 +1,87 @@
1
+ module StackedConfig
2
+ module SourceHelper
3
+
4
+ OS_FLAVOURS = {
5
+ mingw32: :windows,
6
+ linux: :unix
7
+ }
8
+ DEFAULT_OS_FLAVOUR = :unix
9
+
10
+ SYSTEM_CONFIG_ROOT = {
11
+ windows: [File.join(ENV['systemRoot'] || '', 'Config')],
12
+ unix: '/etc'
13
+ }
14
+
15
+ USER_CONFIG_ROOT = {
16
+ windows: ENV['APPDATA'],
17
+ unix: ENV['HOME']
18
+ }
19
+
20
+ EXTENSIONS = %w(conf CONF cfg CFG yml YML yaml YAML)
21
+
22
+ def self.os_flavour
23
+ OS_FLAVOURS[RbConfig::CONFIG['target_os'].to_sym] || DEFAULT_OS_FLAVOUR
24
+ end
25
+
26
+ def self.supported_oses
27
+ OS_FLAVOURS.values.sort.uniq
28
+ end
29
+
30
+ def self.system_config_root
31
+ SYSTEM_CONFIG_ROOT[os_flavour]
32
+ end
33
+
34
+ def self.user_config_root
35
+ USER_CONFIG_ROOT[os_flavour]
36
+ end
37
+
38
+
39
+ def supported_oses
40
+ StackedConfig::SourceHelper.supported_oses
41
+ end
42
+
43
+ def os_flavour
44
+ @os_flavour ||= StackedConfig::SourceHelper.os_flavour
45
+ end
46
+
47
+ def system_config_root
48
+ StackedConfig::SourceHelper.system_config_root
49
+ end
50
+
51
+ def user_config_root
52
+ StackedConfig::SourceHelper.user_config_root
53
+ end
54
+
55
+ def set_config_file(places)
56
+ @file_name = nil
57
+ places.each do |path_array|
58
+ # Perform path substitutions
59
+ potential_config_file = File.join(path_array.map do |path_part|
60
+ perform_substitutions path_part
61
+ end)
62
+ # Try to find config file with extension
63
+ EXTENSIONS.each do |extension|
64
+ file = potential_config_file.gsub '##EXTENSION##', extension
65
+ if File.readable? file
66
+ @file_name = file
67
+ return @file_name
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+
74
+
75
+ def perform_substitutions path_part
76
+ res = path_part.dup
77
+ res.gsub! '##SYSTEM_CONFIG_ROOT##', system_config_root
78
+ res.gsub! '##USER_CONFIG_ROOT##', user_config_root
79
+
80
+ exec_name = manager.nil? ? File.basename($PROGRAM_NAME) : manager.executable_name
81
+ res.gsub! '##PROGRAM_NAME##', exec_name
82
+ res
83
+ end
84
+
85
+
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module StackedConfig
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'super_stack'
2
+ require 'slop'
3
+
4
+ require 'stacked_config/version'
5
+ require 'stacked_config/source_helper'
6
+ require 'stacked_config/program_description_helper'
7
+ require 'stacked_config/layers/generic_layer'
8
+ require 'stacked_config/layers/system_layer'
9
+ require 'stacked_config/layers/global_layer'
10
+ require 'stacked_config/layers/user_layer'
11
+ require 'stacked_config/layers/command_line_layer'
12
+ require 'stacked_config/orchestrator'
13
+
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe StackedConfig::Layers::CommandLineLayer do
5
+ subject { StackedConfig::Layers::CommandLineLayer.new }
6
+
7
+ it 'should have some default command line options defined' do
8
+ expect(subject.length > 0).to be_truthy
9
+ end
10
+
11
+ it 'should have a "help" command line options defined' do
12
+ expect(subject.keys.include? :help).to be_truthy
13
+ end
14
+
15
+ it 'should have a "auto" command line options defined' do
16
+ expect(subject.keys.include? :auto).to be_truthy
17
+ end
18
+
19
+ it 'should have a "simulate" command line options defined' do
20
+ expect(subject.keys.include? :simulate).to be_truthy
21
+ end
22
+
23
+ it 'should have a "verbose" command line options defined' do
24
+ expect(subject.keys.include? :verbose).to be_truthy
25
+ end
26
+
27
+
28
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe StackedConfig::Layers::GlobalLayer do
5
+
6
+ # subject is a modified SystemLayer to redirect system_config_root to the test directory
7
+ subject {
8
+ s = StackedConfig::Layers::GlobalLayer.new
9
+ real_root_path = s.system_config_root
10
+ os = s.os_flavour.to_s
11
+ gem_path = File.expand_path '../..', __FILE__
12
+ allow(s).to receive(:system_config_root) {File.join(gem_path, 'test', os, real_root_path) }
13
+ s.rescan
14
+ s
15
+ }
16
+
17
+ it 'should return the path of the first matching config file it found' do
18
+ expect(subject.file_name).not_to be_nil
19
+ end
20
+
21
+ it 'should have an empty file_name if not present' do
22
+ allow(File).to receive(:readable?) {false}
23
+ subject.rescan
24
+ expect(subject.file_name).to be_nil
25
+ end
26
+
27
+ it 'should enable to load the file' do
28
+ expect(subject[:an_array]).to be_nil
29
+ subject.load
30
+ expect(subject[:an_array]).to be_an Array
31
+ end
32
+
33
+
34
+
35
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe StackedConfig::Orchestrator do
5
+
6
+ subject {
7
+ # Patching SourceHelper to find test config files in this gem test directory instead of from the system.
8
+ os = StackedConfig::SourceHelper.os_flavour
9
+ gem_path = File.expand_path '../..', __FILE__
10
+ altered_sys_conf_root = File.join gem_path, 'test', os.to_s, StackedConfig::SourceHelper::SYSTEM_CONFIG_ROOT[os]
11
+ altered_user_conf_root = File.join gem_path, 'test', 'user'
12
+
13
+ allow(StackedConfig::SourceHelper).to receive(:system_config_root) { altered_sys_conf_root }
14
+ allow(StackedConfig::SourceHelper).to receive(:user_config_root) { altered_user_conf_root }
15
+
16
+ StackedConfig::Orchestrator.new
17
+ }
18
+
19
+ it 'should have multiple layers' do
20
+ expect(subject.layers.length > 0).to be_truthy
21
+ # puts '#' * 80
22
+ # puts subject.layers.to_yaml
23
+ # puts '#' * 80
24
+ # puts subject[].to_yaml
25
+ # puts '#' * 80
26
+ # puts subject.command_line_layer.help
27
+ end
28
+
29
+
30
+ context 'when changing the executable_name' do
31
+
32
+ it 'should reload all config files' do
33
+ expect(subject[:user_defined]).not_to be_nil
34
+ expect(subject[:weird_property]).to be_nil
35
+ subject.executable_name = 'weird_name'
36
+ expect(subject[:user_defined]).to be_nil
37
+ expect(subject[:weird_property]).not_to be_nil
38
+ end
39
+
40
+ it 'should keep the modified values' do
41
+ subject[:modified_value] = :pipo
42
+ subject.executable_name = 'weird_name'
43
+ expect(subject[:modified_value]).not_to be_nil
44
+ end
45
+
46
+ end
47
+
48
+ context 'when setup by default, priorities should be defined in the Unix standard way' do
49
+
50
+ it 'should have the system layer evaluated first' do
51
+ expect(subject.system_layer).to be subject.to_a.first
52
+ end
53
+
54
+ it 'should have the global layer evaluated in second' do
55
+ expect(subject.global_layer).to be subject.to_a[1]
56
+ end
57
+
58
+ it 'should have the user layer evaluated in third' do
59
+ expect(subject.user_layer).to be subject.to_a[2]
60
+ end
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]
64
+ end
65
+
66
+ it 'should have the writable layer evaluated last' do
67
+ expect(subject.write_layer).to be subject.to_a.last
68
+ end
69
+
70
+ end
71
+
72
+
73
+
74
+
75
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe StackedConfig::SourceHelper do
5
+
6
+ subject {
7
+ s = Object.new
8
+ s.extend StackedConfig::SourceHelper
9
+ s
10
+ }
11
+
12
+ it 'should provide an OS flavour' do
13
+ expect(subject.os_flavour).to_not be_nil
14
+ end
15
+
16
+ it 'should provide a system config root' do
17
+ expect(subject.system_config_root).to_not be_nil
18
+ end
19
+
20
+ it 'should provide a user config root' do
21
+ expect(subject.user_config_root).to_not be_nil
22
+ end
23
+
24
+
25
+ end
26
+
@@ -0,0 +1,92 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+
18
+ require 'stacked_config'
19
+
20
+ RSpec.configure do |config|
21
+ # rspec-expectations config goes here. You can use an alternate
22
+ # assertion/expectation library such as wrong or the stdlib/minitest
23
+ # assertions if you prefer.
24
+ config.expect_with :rspec do |expectations|
25
+ # This option will default to `true` in RSpec 4. It makes the `description`
26
+ # and `failure_message` of custom matchers include text for helper methods
27
+ # defined using `chain`, e.g.:
28
+ # be_bigger_than(2).and_smaller_than(4).description
29
+ # # => "be bigger than 2 and smaller than 4"
30
+ # ...rather than:
31
+ # # => "be bigger than 2"
32
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
33
+ end
34
+
35
+ # rspec-mocks config goes here. You can use an alternate test double
36
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
37
+ config.mock_with :rspec do |mocks|
38
+ # Prevents you from mocking or stubbing a method that does not exist on
39
+ # a real object. This is generally recommended, and will default to
40
+ # `true` in RSpec 4.
41
+ mocks.verify_partial_doubles = true
42
+ end
43
+
44
+ # The settings below are suggested to provide a good initial experience
45
+ # with RSpec, but feel free to customize to your heart's content.
46
+ =begin
47
+ # These two settings work together to allow you to limit a spec run
48
+ # to individual examples or groups you care about by tagging them with
49
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
50
+ # get run.
51
+ config.filter_run :focus
52
+ config.run_all_when_everything_filtered = true
53
+
54
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
55
+ # For more details, see:
56
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
57
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
58
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
59
+ config.disable_monkey_patching!
60
+
61
+ # This setting enables warnings. It's recommended, but in some cases may
62
+ # be too noisy due to issues in dependencies.
63
+ config.warnings = true
64
+
65
+ # Many RSpec users commonly either run the entire suite or an individual
66
+ # file, and it's useful to allow more verbose output when running an
67
+ # individual spec file.
68
+ if config.files_to_run.one?
69
+ # Use the documentation formatter for detailed output,
70
+ # unless a formatter has already been configured
71
+ # (e.g. via a command-line flag).
72
+ config.default_formatter = 'doc'
73
+ end
74
+
75
+ # Print the 10 slowest examples and example groups at the
76
+ # end of the spec run, to help surface which specs are running
77
+ # particularly slow.
78
+ config.profile_examples = 10
79
+
80
+ # Run specs in random order to surface order dependencies. If you find an
81
+ # order dependency and want to debug it, you can fix the order by providing
82
+ # the seed, which is printed after each run.
83
+ # --seed 1234
84
+ config.order = :random
85
+
86
+ # Seed global randomization in this process using the `--seed` CLI option.
87
+ # Setting this allows you to use `--seed` to deterministically reproduce
88
+ # test failures related to randomization by passing the same `--seed` value
89
+ # as the one that triggered the failure.
90
+ Kernel.srand config.seed
91
+ =end
92
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe StackedConfig::Layers::SystemLayer do
5
+
6
+ # subject is a modified SystemLayer to redirect system_config_root to the test directory
7
+ subject {
8
+ s = StackedConfig::Layers::SystemLayer.new
9
+ real_root_path = s.system_config_root
10
+ os = s.os_flavour.to_s
11
+ gem_path = File.expand_path '../..', __FILE__
12
+ allow(s).to receive(:system_config_root) {File.join(gem_path, 'test', os, real_root_path) }
13
+ s.rescan
14
+ s
15
+ }
16
+
17
+ it 'should return the path of the first matching config file it found' do
18
+ expect(subject.file_name).not_to be_nil
19
+ end
20
+
21
+ it 'should have an empty file_name if not present' do
22
+ allow(File).to receive(:readable?) {false}
23
+ subject.rescan
24
+ expect(subject.file_name).to be_nil
25
+ end
26
+
27
+ it 'should enable to load the file' do
28
+ expect(subject[:stacked_config_copyright]).to be_nil
29
+ subject.load
30
+ expect(subject[:stacked_config_copyright]).not_to be_nil
31
+ end
32
+
33
+
34
+
35
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe StackedConfig::Layers::UserLayer do
5
+
6
+ # subject is a modified SystemLayer to redirect system_config_root to the test directory
7
+ subject {
8
+ s = StackedConfig::Layers::UserLayer.new
9
+ os = s.os_flavour.to_s
10
+ gem_path = File.expand_path '../..', __FILE__
11
+ allow(s).to receive(:user_config_root) {File.join(gem_path, 'test', 'user') }
12
+ s.rescan
13
+ s
14
+ }
15
+
16
+ it 'should return the path of the first matching config file it found' do
17
+ expect(subject.file_name).not_to be_nil
18
+ end
19
+
20
+ it 'should have an empty file_name if not present' do
21
+ allow(File).to receive(:readable?) {false}
22
+ subject.rescan
23
+ expect(subject.file_name).to be_nil
24
+ end
25
+
26
+ it 'should enable to load the file' do
27
+ expect(subject[:an_array]).to be_nil
28
+ subject.load
29
+ expect(subject[:an_array]).to be_an Array
30
+ end
31
+
32
+
33
+
34
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stacked_config/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'stacked_config'
8
+ spec.version = StackedConfig::VERSION
9
+ spec.authors = ['Laurent B.']
10
+ spec.email = ['lbnetid+gh@gmail.com']
11
+ spec.summary = %q{Manages config files according to standard policy.}
12
+ spec.description = %q{A config file manager on steroids focusing on places.}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.5'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'pry'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+
26
+ spec.add_dependency 'super_stack', '~> 0.2', '>= 0.2.3'
27
+ spec.add_dependency 'slop'
28
+
29
+ end
@@ -0,0 +1,7 @@
1
+ # This is supposed to be a file at "global" level.
2
+ # It is dedicated to configuration for all users running the program rspec
3
+ # To be used at administrator level only
4
+
5
+ an_array:
6
+ - defined at global level
7
+ - pretty cool (global)
@@ -0,0 +1,5 @@
1
+ # This is supposed to be a file at "system" level.
2
+ # It is dedicated to configuration for all gems that would use the stacked_config gem.
3
+ # To be used at administrator level only
4
+
5
+ stacked_config_copyright: (c)2014 L.Briais under MIT license
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stacked_config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Laurent B.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: super_stack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.2'
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 0.2.3
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '0.2'
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: 0.2.3
89
+ - !ruby/object:Gem::Dependency
90
+ name: slop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ description: A config file manager on steroids focusing on places.
104
+ email:
105
+ - lbnetid+gh@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - .gitignore
111
+ - .rspec
112
+ - Gemfile
113
+ - LICENSE.txt
114
+ - README.md
115
+ - Rakefile
116
+ - lib/stacked_config.rb
117
+ - lib/stacked_config/layers/command_line_layer.rb
118
+ - lib/stacked_config/layers/generic_layer.rb
119
+ - lib/stacked_config/layers/global_layer.rb
120
+ - lib/stacked_config/layers/system_layer.rb
121
+ - lib/stacked_config/layers/user_layer.rb
122
+ - lib/stacked_config/orchestrator.rb
123
+ - lib/stacked_config/program_description_helper.rb
124
+ - lib/stacked_config/source_helper.rb
125
+ - lib/stacked_config/version.rb
126
+ - spec/command_line_layer_spec.rb
127
+ - spec/global_layer_spec.rb
128
+ - spec/orchestrator_spec.rb
129
+ - spec/source_helper_spec.rb
130
+ - spec/spec_helper.rb
131
+ - spec/system_layer_spec.rb
132
+ - spec/user_layer_spec.rb
133
+ - stacked_config.gemspec
134
+ - test/unix/etc/rspec/rspec.yml
135
+ - test/unix/etc/stacked_config.yml
136
+ homepage: ''
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.0.0
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Manages config files according to standard policy.
160
+ test_files:
161
+ - spec/command_line_layer_spec.rb
162
+ - spec/global_layer_spec.rb
163
+ - spec/orchestrator_spec.rb
164
+ - spec/source_helper_spec.rb
165
+ - spec/spec_helper.rb
166
+ - spec/system_layer_spec.rb
167
+ - spec/user_layer_spec.rb
168
+ - test/unix/etc/rspec/rspec.yml
169
+ - test/unix/etc/stacked_config.yml