conferrable 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +8 -0
- data/.gitignore +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +32 -0
- data/LICENSE +7 -0
- data/README.md +95 -0
- data/conferrable.gemspec +25 -0
- data/lib/conferrable/conferrable.rb +68 -0
- data/lib/conferrable/configuration.rb +34 -0
- data/lib/conferrable/entry.rb +84 -0
- data/lib/conferrable/file_based_configuration.rb +27 -0
- data/lib/conferrable/file_utilities.rb +32 -0
- data/lib/conferrable/version.rb +10 -0
- data/spec/conferrable_spec.rb +62 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/entry_spec.rb +31 -0
- data/spec/file_based_configuration_spec.rb +73 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b4e80fa2a3db3e61e5e423d6cfb046e28ba2d0d7
|
4
|
+
data.tar.gz: d831fe504d2ede66c549b5c39b22b02f932eace4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6290b5fb9e797fa2d7c66d2539194003363eceffa79184dfa45e6f338e87ca2ef680116efd53fc0c5510fc51b14f1facd5bbd2043286d1b942e60c748359e566
|
7
|
+
data.tar.gz: 18d2fee082ac9e97d2627cc9b3b153744626a573f4a16d1f0675b4047b109afe7f3770e40d344c536e0c9ac0f73bac447f6599ac548e36f3f39c2d68fab111a3
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.7
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
conferrable (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rspec (3.8.0)
|
11
|
+
rspec-core (~> 3.8.0)
|
12
|
+
rspec-expectations (~> 3.8.0)
|
13
|
+
rspec-mocks (~> 3.8.0)
|
14
|
+
rspec-core (3.8.0)
|
15
|
+
rspec-support (~> 3.8.0)
|
16
|
+
rspec-expectations (3.8.1)
|
17
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
18
|
+
rspec-support (~> 3.8.0)
|
19
|
+
rspec-mocks (3.8.0)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.8.0)
|
22
|
+
rspec-support (3.8.0)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
conferrable!
|
29
|
+
rspec
|
30
|
+
|
31
|
+
BUNDLED WITH
|
32
|
+
1.16.3
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2018 Blue Marble Payroll, LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# Conferrable
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/bluemarblepayroll/conferrable.svg?branch=master)](https://travis-ci.org/bluemarblepayroll/conferrable)
|
4
|
+
|
5
|
+
We have seen our applications gain more and more static configuration files over time. A common library we use on a daily basis is these configuration file loaders. Conferrable standardizes how we interact with these static YAML configuration files. It offers a simple and extendable API for dealing with the following scenarios:
|
6
|
+
|
7
|
+
* Load a YAML file
|
8
|
+
* Load a directory of YAML files
|
9
|
+
* Load multiple YAML files
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
To install through Rubygems:
|
14
|
+
|
15
|
+
````
|
16
|
+
gem install install conferrable
|
17
|
+
````
|
18
|
+
|
19
|
+
You can also add this to your Gemfile:
|
20
|
+
|
21
|
+
````
|
22
|
+
bundle add conferrable
|
23
|
+
````
|
24
|
+
|
25
|
+
## Examples
|
26
|
+
|
27
|
+
### Simple Example
|
28
|
+
|
29
|
+
Lets say we have a configuration file located at:
|
30
|
+
|
31
|
+
````
|
32
|
+
<app root>/config/config.yml.erb
|
33
|
+
````
|
34
|
+
|
35
|
+
We can access this by:
|
36
|
+
|
37
|
+
````
|
38
|
+
config = Conferrable.get_config # config will be a hash
|
39
|
+
````
|
40
|
+
|
41
|
+
### Multiple File Example
|
42
|
+
|
43
|
+
Building on the simple example, say we have two configuration files:
|
44
|
+
|
45
|
+
````
|
46
|
+
<app root>/config/config1.yml.erb
|
47
|
+
<app root>/config/config2.yml.erb
|
48
|
+
````
|
49
|
+
|
50
|
+
We can now explicitly set the files:
|
51
|
+
|
52
|
+
````
|
53
|
+
files = [
|
54
|
+
'./config/config1.yml.erb',
|
55
|
+
'./config/config2.yml.erb',
|
56
|
+
]
|
57
|
+
|
58
|
+
Conferrable.set_filenames(:config, files)
|
59
|
+
|
60
|
+
config = Conferrable.get_config # config will be a hash
|
61
|
+
````
|
62
|
+
|
63
|
+
Alternatively, we could use a directory:
|
64
|
+
|
65
|
+
````
|
66
|
+
Conferrable.set_filenames(:config, './config')
|
67
|
+
|
68
|
+
config = Conferrable.get_config # config will be a hash
|
69
|
+
````
|
70
|
+
|
71
|
+
Note that the files will be loaded in alphabetical order.
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
### Development Environment Configuration
|
76
|
+
|
77
|
+
Basic steps to take to get this repository compiling:
|
78
|
+
|
79
|
+
1. Install [Ruby](https://www.ruby-lang.org/en/documentation/installation/) (check conferrable.gemspec for versions supported)
|
80
|
+
2. Install bundler (gem install bundler)
|
81
|
+
3. Clone the repository (git clone git@github.com:bluemarblepayroll/conferrable.git)
|
82
|
+
4. Navigate to the root folder (cd conferrable)
|
83
|
+
5. Install dependencies (bundle)
|
84
|
+
|
85
|
+
### Running Tests
|
86
|
+
|
87
|
+
To execute the test suite run:
|
88
|
+
|
89
|
+
````
|
90
|
+
rspec
|
91
|
+
````
|
92
|
+
|
93
|
+
## License
|
94
|
+
|
95
|
+
This project is MIT Licensed.
|
data/conferrable.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "./lib/conferrable/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'conferrable'
|
5
|
+
s.version = Conferrable::VERSION
|
6
|
+
s.summary = "Simple YAML file-based configuration management"
|
7
|
+
|
8
|
+
s.description = <<-EOS
|
9
|
+
We have seen our applications gain more and more static configuration files over time.
|
10
|
+
A common library we use on a daily basis is these configuration file loaders.
|
11
|
+
Conferrable standardizes how we interact with these static YAML configuration files.
|
12
|
+
EOS
|
13
|
+
|
14
|
+
s.authors = [ 'Matthew Ruggio' ]
|
15
|
+
s.email = [ 'mruggio@bluemarblepayroll.com' ]
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.homepage = 'https://github.com/bluemarblepayroll/conferrale'
|
20
|
+
s.license = 'MIT'
|
21
|
+
|
22
|
+
s.required_ruby_version = '>= 2.3.1'
|
23
|
+
|
24
|
+
s.add_development_dependency('rspec')
|
25
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
3
|
+
#
|
4
|
+
# This source code is licensed under the MIT license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'yaml'
|
9
|
+
require 'erb'
|
10
|
+
|
11
|
+
require_relative 'file_utilities'
|
12
|
+
require_relative 'configuration'
|
13
|
+
require_relative 'file_based_configuration'
|
14
|
+
require_relative 'entry'
|
15
|
+
|
16
|
+
module Conferrable
|
17
|
+
|
18
|
+
GET_PREFIX_MATCHER_REGEX = /^get_(.+)$/
|
19
|
+
GET_PREFIX_REGEX = /^get_/
|
20
|
+
|
21
|
+
class << self
|
22
|
+
|
23
|
+
def clear!
|
24
|
+
@entries = {}
|
25
|
+
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_filenames(key, filenames)
|
30
|
+
entry(key).filenames = filenames
|
31
|
+
end
|
32
|
+
|
33
|
+
def [](key)
|
34
|
+
get(key)
|
35
|
+
end
|
36
|
+
|
37
|
+
def get(key)
|
38
|
+
entry(key).all
|
39
|
+
end
|
40
|
+
|
41
|
+
def entry(key)
|
42
|
+
clear! unless @entries
|
43
|
+
|
44
|
+
@entries[key.to_s] = Entry.new(key) unless @entries[key.to_s]
|
45
|
+
|
46
|
+
@entries[key.to_s]
|
47
|
+
end
|
48
|
+
|
49
|
+
def method_missing(method_sym, *arguments, &block)
|
50
|
+
if method_sym.to_s =~ GET_PREFIX_MATCHER_REGEX
|
51
|
+
get(keyify(method_sym))
|
52
|
+
else
|
53
|
+
super
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def respond_to_missing?(method_sym, include_private = false)
|
58
|
+
method_sym.to_s =~ GET_PREFIX_MATCHER_REGEX || super
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def keyify(val)
|
64
|
+
val.to_s.sub(GET_PREFIX_REGEX, '')
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
3
|
+
#
|
4
|
+
# This source code is licensed under the MIT license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
#
|
7
|
+
|
8
|
+
module Conferrable
|
9
|
+
class Configuration
|
10
|
+
|
11
|
+
def initialize(*configs)
|
12
|
+
load!(configs)
|
13
|
+
end
|
14
|
+
|
15
|
+
def all
|
16
|
+
@all || {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def load!(*configs)
|
20
|
+
configs.flatten.compact.each { |c| overlay(c) }
|
21
|
+
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def overlay(config)
|
28
|
+
@all = {} unless @all
|
29
|
+
|
30
|
+
@all.merge!(config || {})
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
3
|
+
#
|
4
|
+
# This source code is licensed under the MIT license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
#
|
7
|
+
|
8
|
+
module Conferrable
|
9
|
+
class Entry
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def default_folder
|
14
|
+
@default_folder || File.join('.', 'config')
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_folder=(path)
|
18
|
+
@default_folder = path
|
19
|
+
end
|
20
|
+
|
21
|
+
def default_file(name)
|
22
|
+
File.join(default_folder, "#{name}.yml.erb")
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :key
|
28
|
+
|
29
|
+
attr_accessor :filenames
|
30
|
+
|
31
|
+
def initialize(key, filenames: nil)
|
32
|
+
raise ArgumentError, 'key is required' unless key && key.to_s.length > 0
|
33
|
+
|
34
|
+
@key = key.to_s
|
35
|
+
@filenames = filenames
|
36
|
+
end
|
37
|
+
|
38
|
+
def filenames=(filenames)
|
39
|
+
protected!
|
40
|
+
|
41
|
+
@filenames = filenames
|
42
|
+
end
|
43
|
+
|
44
|
+
def loaded?
|
45
|
+
@loaded || false
|
46
|
+
end
|
47
|
+
|
48
|
+
def all
|
49
|
+
load!
|
50
|
+
|
51
|
+
@configuration&.all || {}
|
52
|
+
end
|
53
|
+
|
54
|
+
def loaded_filenames
|
55
|
+
@configuration&.loaded_filenames || []
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def protected!
|
61
|
+
raise ArgumentError, "[Illegal] #{key} config store has been re-configured after it was loaded." if loaded?
|
62
|
+
end
|
63
|
+
|
64
|
+
def loaded!
|
65
|
+
@loaded = true
|
66
|
+
end
|
67
|
+
|
68
|
+
def load!
|
69
|
+
if loaded?
|
70
|
+
@configuration.load!
|
71
|
+
return
|
72
|
+
end
|
73
|
+
|
74
|
+
names = Array(filenames).flatten
|
75
|
+
|
76
|
+
names = [ self.class.default_file(key) ] if names.length == 0
|
77
|
+
|
78
|
+
@configuration = FileBasedConfiguration.new(names)
|
79
|
+
|
80
|
+
loaded!
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
3
|
+
#
|
4
|
+
# This source code is licensed under the MIT license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
#
|
7
|
+
|
8
|
+
module Conferrable
|
9
|
+
class FileBasedConfiguration < Configuration
|
10
|
+
|
11
|
+
attr_reader :filenames, :loaded_filenames
|
12
|
+
|
13
|
+
def initialize(*filenames)
|
14
|
+
@filenames = filenames.flatten
|
15
|
+
@loaded_filenames = FileUtilities.resolve(@filenames)
|
16
|
+
|
17
|
+
load!
|
18
|
+
end
|
19
|
+
|
20
|
+
def load!
|
21
|
+
configs = @loaded_filenames.map { |f| FileUtilities.read(f) }
|
22
|
+
|
23
|
+
super(configs)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
3
|
+
#
|
4
|
+
# This source code is licensed under the MIT license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
#
|
7
|
+
|
8
|
+
module Conferrable
|
9
|
+
class FileUtilities
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def resolve(filenames)
|
13
|
+
Array(filenames).flatten.map do |filename|
|
14
|
+
next unless filename && filename.to_s.length > 0
|
15
|
+
|
16
|
+
if File.exist?(filename) && File.directory?(filename)
|
17
|
+
Dir.glob(File.join(filename, '**', '*.yml.erb')).select { |f| !File.directory?(f) }
|
18
|
+
elsif File.exist?(filename)
|
19
|
+
filename
|
20
|
+
else
|
21
|
+
raise ArgumentError, "Cannot find file: #{filename} => #{File.expand_path(filename)}"
|
22
|
+
end
|
23
|
+
end.flatten
|
24
|
+
end
|
25
|
+
|
26
|
+
def read(filename)
|
27
|
+
YAML.load(ERB.new(IO.read(filename)).result)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
3
|
+
#
|
4
|
+
# This source code is licensed under the MIT license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
#
|
7
|
+
|
8
|
+
require './lib/conferrable/conferrable'
|
9
|
+
|
10
|
+
describe Conferrable do
|
11
|
+
|
12
|
+
let(:default_file_path) { './config/file1.yml.erb' }
|
13
|
+
let(:default_abs_file_path) { File.expand_path(default_file_path) }
|
14
|
+
|
15
|
+
let(:default_file) { "admin: true" }
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
allow(::Conferrable::FileUtilities).to receive(:resolve).with([default_file_path]).and_return([default_abs_file_path])
|
19
|
+
|
20
|
+
allow(IO).to receive(:read).with(default_abs_file_path).and_return(default_file)
|
21
|
+
end
|
22
|
+
|
23
|
+
after(:each) do
|
24
|
+
Conferrable.clear!
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should load default file using brackets method' do
|
28
|
+
admin_value = Conferrable[:file1]['admin']
|
29
|
+
|
30
|
+
expect(admin_value).to be true
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should load default file using get method' do
|
34
|
+
admin_value = Conferrable.get(:file1)['admin']
|
35
|
+
|
36
|
+
expect(admin_value).to be true
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should load default file using get_* method_missing' do
|
40
|
+
admin_value = Conferrable.get_file1['admin']
|
41
|
+
|
42
|
+
expect(admin_value).to be true
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should set the filenames and load the correct file' do
|
46
|
+
Conferrable.set_filenames(:another_file, default_file_path)
|
47
|
+
|
48
|
+
admin_value = Conferrable.get_another_file['admin']
|
49
|
+
|
50
|
+
expect(admin_value).to be true
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should not allow you to change the filenames after its used the first time' do
|
54
|
+
admin_value = Conferrable.get_file1['admin']
|
55
|
+
expect(admin_value).to be true
|
56
|
+
|
57
|
+
expect do
|
58
|
+
Conferrable.set_filenames(:file1, 'something_else.yml.erb')
|
59
|
+
end.to raise_error(ArgumentError)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
3
|
+
#
|
4
|
+
# This source code is licensed under the MIT license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
#
|
7
|
+
|
8
|
+
require './lib/conferrable/conferrable'
|
9
|
+
|
10
|
+
describe Conferrable::Configuration do
|
11
|
+
|
12
|
+
it 'should accept no initialization arguments' do
|
13
|
+
config = Conferrable::Configuration.new
|
14
|
+
|
15
|
+
expect(config.all['doesnt_exist']).to be nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should accept multiple hashes as initialization arguments' do
|
19
|
+
c1 = { 'admin' => true }
|
20
|
+
c2 = { 'admin' => false }
|
21
|
+
|
22
|
+
config = Conferrable::Configuration.new(c1, c2)
|
23
|
+
|
24
|
+
expect(config.all['admin']).to be false
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should accept one hash as an initialization argument' do
|
28
|
+
config = Conferrable::Configuration.new('admin' => true)
|
29
|
+
|
30
|
+
expect(config.all['admin']).to be true
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should allow get to work with nested depths' do
|
34
|
+
c1 = { 'options' => { 'admin' => true } }
|
35
|
+
c2 = { 'options' => { 'admin' => false } }
|
36
|
+
|
37
|
+
config = Conferrable::Configuration.new(c1, c2)
|
38
|
+
|
39
|
+
expect(config.all.dig('options', 'admin')).to be false
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/spec/entry_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
3
|
+
#
|
4
|
+
# This source code is licensed under the MIT license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
#
|
7
|
+
|
8
|
+
require './lib/conferrable/conferrable'
|
9
|
+
|
10
|
+
describe Conferrable::Entry do
|
11
|
+
|
12
|
+
let(:default_file_path) { './config/file1.yml.erb' }
|
13
|
+
let(:default_abs_file_path) { File.expand_path(default_file_path) }
|
14
|
+
|
15
|
+
let(:default_file) { "admin: true" }
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
allow(::Conferrable::FileUtilities).to receive(:resolve).with([default_file_path]).and_return([default_abs_file_path])
|
19
|
+
|
20
|
+
allow(IO).to receive(:read).with(default_abs_file_path).and_return(default_file)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should load default file' do
|
24
|
+
entry = Conferrable::Entry.new(:file1)
|
25
|
+
|
26
|
+
admin_value = entry.all['admin']
|
27
|
+
|
28
|
+
expect(admin_value).to be true
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
3
|
+
#
|
4
|
+
# This source code is licensed under the MIT license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
#
|
7
|
+
|
8
|
+
require './lib/conferrable/conferrable'
|
9
|
+
|
10
|
+
describe Conferrable::FileBasedConfiguration do
|
11
|
+
|
12
|
+
let(:file1_path) { File.expand_path('spec/files/file1.yml.erb') }
|
13
|
+
let(:file2_path) { File.expand_path('spec/files/file2.yml.erb') }
|
14
|
+
let(:files_path) { File.expand_path('spec/files') }
|
15
|
+
let(:files) { [ file1_path, file2_path ]}
|
16
|
+
|
17
|
+
let(:file1) { "admin: true" }
|
18
|
+
let(:file2) { "admin: false" }
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
allow(::Conferrable::FileUtilities).to receive(:resolve).with([]).and_return([])
|
22
|
+
allow(::Conferrable::FileUtilities).to receive(:resolve).with([file1_path]).and_return([file1_path])
|
23
|
+
allow(::Conferrable::FileUtilities).to receive(:resolve).with([file2_path]).and_return([file2_path])
|
24
|
+
allow(::Conferrable::FileUtilities).to receive(:resolve).with([files_path]).and_return(files)
|
25
|
+
allow(::Conferrable::FileUtilities).to receive(:resolve).with([files]).and_return(files)
|
26
|
+
allow(::Conferrable::FileUtilities).to receive(:resolve).with(files).and_return(files)
|
27
|
+
|
28
|
+
allow(IO).to receive(:read).with(file1_path).and_return(file1)
|
29
|
+
allow(IO).to receive(:read).with(file2_path).and_return(file2)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should allow no files' do
|
33
|
+
config = Conferrable::FileBasedConfiguration.new
|
34
|
+
|
35
|
+
admin_value = config.all['admin']
|
36
|
+
|
37
|
+
expect(admin_value).to be nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should load single file' do
|
41
|
+
config = Conferrable::FileBasedConfiguration.new(file1_path)
|
42
|
+
|
43
|
+
admin_value = config.all['admin']
|
44
|
+
|
45
|
+
expect(admin_value).to be true
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should load multiple files' do
|
49
|
+
# Test passing in an array
|
50
|
+
config = Conferrable::FileBasedConfiguration.new(files)
|
51
|
+
admin_value = config.all['admin']
|
52
|
+
expect(admin_value).to be false
|
53
|
+
|
54
|
+
# Test passing in multiple arguments
|
55
|
+
config = Conferrable::FileBasedConfiguration.new(*files)
|
56
|
+
admin_value = config.all['admin']
|
57
|
+
expect(admin_value).to be false
|
58
|
+
|
59
|
+
# Test passing in an nested arrays
|
60
|
+
config = Conferrable::FileBasedConfiguration.new([ [ files ] ])
|
61
|
+
admin_value = config.all['admin']
|
62
|
+
expect(admin_value).to be false
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should load directories' do
|
66
|
+
config = Conferrable::FileBasedConfiguration.new(files_path)
|
67
|
+
admin_value = config.all['admin']
|
68
|
+
|
69
|
+
expect(admin_value).to be false
|
70
|
+
expect(config.loaded_filenames).to eq(files)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: conferrable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Ruggio
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: |2
|
28
|
+
We have seen our applications gain more and more static configuration files over time.
|
29
|
+
A common library we use on a daily basis is these configuration file loaders.
|
30
|
+
Conferrable standardizes how we interact with these static YAML configuration files.
|
31
|
+
email:
|
32
|
+
- mruggio@bluemarblepayroll.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- ".editorconfig"
|
38
|
+
- ".gitignore"
|
39
|
+
- ".ruby-version"
|
40
|
+
- ".travis.yml"
|
41
|
+
- Gemfile
|
42
|
+
- Gemfile.lock
|
43
|
+
- LICENSE
|
44
|
+
- README.md
|
45
|
+
- conferrable.gemspec
|
46
|
+
- lib/conferrable/conferrable.rb
|
47
|
+
- lib/conferrable/configuration.rb
|
48
|
+
- lib/conferrable/entry.rb
|
49
|
+
- lib/conferrable/file_based_configuration.rb
|
50
|
+
- lib/conferrable/file_utilities.rb
|
51
|
+
- lib/conferrable/version.rb
|
52
|
+
- spec/conferrable_spec.rb
|
53
|
+
- spec/configuration_spec.rb
|
54
|
+
- spec/entry_spec.rb
|
55
|
+
- spec/file_based_configuration_spec.rb
|
56
|
+
homepage: https://github.com/bluemarblepayroll/conferrale
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.3.1
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.5.2.3
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Simple YAML file-based configuration management
|
80
|
+
test_files:
|
81
|
+
- spec/conferrable_spec.rb
|
82
|
+
- spec/configuration_spec.rb
|
83
|
+
- spec/entry_spec.rb
|
84
|
+
- spec/file_based_configuration_spec.rb
|