isomer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/isomer.gemspec +24 -0
- data/lib/isomer.rb +13 -0
- data/lib/isomer/base.rb +23 -0
- data/lib/isomer/errors.rb +2 -0
- data/lib/isomer/parameter.rb +18 -0
- data/lib/isomer/sources.rb +19 -0
- data/lib/isomer/sources/base.rb +42 -0
- data/lib/isomer/sources/environment.rb +28 -0
- data/lib/isomer/sources/test.rb +12 -0
- data/lib/isomer/sources/yaml.rb +23 -0
- data/lib/isomer/version.rb +3 -0
- data/spec/isomer/base_spec.rb +45 -0
- data/spec/isomer/parameter_spec.rb +38 -0
- data/spec/isomer/sources/base_spec.rb +47 -0
- data/spec/isomer/sources/environment_spec.rb +47 -0
- data/spec/isomer/sources/yaml_spec.rb +32 -0
- data/spec/isomer/sources_spec.rb +35 -0
- data/spec/isomer_spec.rb +23 -0
- data/spec/spec_helper.rb +20 -0
- metadata +134 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Paul Guelpa
|
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,72 @@
|
|
1
|
+
# Isomer
|
2
|
+
|
3
|
+
[](https://travis-ci.org/pguelpa/isomer)
|
4
|
+
|
5
|
+
Isomer is a gem to help manage your application's configuration files.
|
6
|
+
It is built with the following ideas in mind:
|
7
|
+
|
8
|
+
* Easily define, store, and save configuration parameters
|
9
|
+
* Work with YAML files and environment variables
|
10
|
+
* Allow for mapping from file / environment variables to parameter
|
11
|
+
* Allow for required parameters
|
12
|
+
* Allow for default parameters
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'isomer'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install isomer
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
For most configurations, you can use the simple setup approach
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
MY_FANCY_CONFIGURATION = Isomer.configure(:yaml, base: Rails.env) do |config|
|
34
|
+
config.parameter :url # defaults to { required: false, from: 'url', default: nil }
|
35
|
+
config.parameter :api_key
|
36
|
+
config.parameter :timeout
|
37
|
+
|
38
|
+
config.parameter :logger, default: Rails.logger
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
If you have a more complex setup, or want add extra methods to your configuration class, you can create your own.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
class MyFancyConfiguration < Isomer::Base
|
46
|
+
parameter :url # defaults to { required: false, name: 'url', default: nil }
|
47
|
+
parameter :api_key, required: true
|
48
|
+
parameter :timeout
|
49
|
+
|
50
|
+
parameter :logger, default: Rails.logger
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
### Initialize with a YAML file
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
MY_FANCY_CONFIGURATION = MyFancyConfiguration.from(:yaml, file: Rails.root.join('config', 'app_card.yml'), base: Rails.env)
|
58
|
+
```
|
59
|
+
|
60
|
+
### Initialize with environment variables
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
MY_FANCY_CONFIGURATION = MyFancyConfiguration.from(:environment, prefix: 'FANCY_CONFIG_')
|
64
|
+
```
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
1. Fork it
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/isomer.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'isomer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "isomer"
|
8
|
+
spec.version = Isomer::VERSION
|
9
|
+
spec.authors = ["Paul Guelpa"]
|
10
|
+
spec.email = ["paul.guelpa@gmail.com"]
|
11
|
+
spec.description = %q{A general configuration solution}
|
12
|
+
spec.summary = %q{A general configuration solution}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/lib/isomer.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'isomer/version'
|
2
|
+
require_relative 'isomer/errors'
|
3
|
+
require_relative 'isomer/base'
|
4
|
+
require_relative 'isomer/parameter'
|
5
|
+
require_relative 'isomer/sources'
|
6
|
+
|
7
|
+
module Isomer
|
8
|
+
def self.configure(source_type, options)
|
9
|
+
Class.new(Isomer::Base) do
|
10
|
+
yield(self)
|
11
|
+
end.from(source_type, options)
|
12
|
+
end
|
13
|
+
end
|
data/lib/isomer/base.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
class Isomer::Base
|
2
|
+
attr_reader :source, :base
|
3
|
+
|
4
|
+
def self.from(source_type, options = {})
|
5
|
+
source = Isomer::Sources.factory(source_type, @parameters, options)
|
6
|
+
source.load_and_validate
|
7
|
+
|
8
|
+
new(source)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.parameter(id, options = {})
|
12
|
+
parameter = Isomer::Parameter.new(id, options)
|
13
|
+
(@parameters ||= []) << parameter
|
14
|
+
|
15
|
+
define_method(id) do
|
16
|
+
source.for(parameter)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(source)
|
21
|
+
@source = source
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Isomer::Parameter
|
2
|
+
attr_reader :default
|
3
|
+
|
4
|
+
def initialize(id, options)
|
5
|
+
@id = id
|
6
|
+
@required = options[:required] || false
|
7
|
+
@from = options[:from]
|
8
|
+
@default = options[:default]
|
9
|
+
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
(@from || @id).to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def required?
|
16
|
+
@required === true
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Isomer::Sources
|
2
|
+
def self.factory(type, parameters=[], options={})
|
3
|
+
case type
|
4
|
+
when :test
|
5
|
+
Isomer::Sources::Test.new(parameters, options)
|
6
|
+
when :yaml
|
7
|
+
Isomer::Sources::Yaml.new(parameters, options)
|
8
|
+
when :environment
|
9
|
+
Isomer::Sources::Environment.new(parameters, options)
|
10
|
+
else
|
11
|
+
raise "Unknown source type #{source_type}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require_relative 'sources/base'
|
17
|
+
require_relative 'sources/test'
|
18
|
+
require_relative 'sources/yaml'
|
19
|
+
require_relative 'sources/environment'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Isomer::Sources::Base
|
2
|
+
attr_reader :parameters, :configuration, :errors
|
3
|
+
|
4
|
+
def initialize(parameters)
|
5
|
+
@parameters = parameters
|
6
|
+
@errors = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def load_and_validate
|
10
|
+
load
|
11
|
+
validate
|
12
|
+
end
|
13
|
+
|
14
|
+
def load
|
15
|
+
raise NotImplementedError, "You must implement 'load' in #{self.class.name}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate
|
19
|
+
parameters.each do |parameter|
|
20
|
+
if parameter.required?
|
21
|
+
value = configuration[parameter.name]
|
22
|
+
@errors << "#{parameter.name} is required" if valid(value)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
raise Isomer::RequiredParameterError, errors.join(', ') if !errors.empty?
|
27
|
+
end
|
28
|
+
|
29
|
+
def for(parameter)
|
30
|
+
configuration[parameter.name] || parameter.default
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def valid(value)
|
36
|
+
if value.respond_to?(:empty)
|
37
|
+
value.empty?
|
38
|
+
else
|
39
|
+
value.nil?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Isomer::Sources::Environment < Isomer::Sources::Base
|
2
|
+
attr_reader :prefix
|
3
|
+
|
4
|
+
def initialize(parameters, options={})
|
5
|
+
@convert_case = options.has_key?(:convert_case) ? options[:convert_case] : true
|
6
|
+
@prefix = options[:prefix]
|
7
|
+
|
8
|
+
super(parameters)
|
9
|
+
end
|
10
|
+
|
11
|
+
def load
|
12
|
+
@configuration = {}
|
13
|
+
parameters.each do |parameter|
|
14
|
+
@configuration[parameter.name] = ENV[ convert_name(parameter.name) ]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def convert_case?
|
19
|
+
@convert_case
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def convert_name(name)
|
25
|
+
converted = [prefix, name].compact.join
|
26
|
+
convert_case? ? converted.upcase : converted
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class Isomer::Sources::Yaml < Isomer::Sources::Base
|
4
|
+
attr_reader :file, :base
|
5
|
+
|
6
|
+
def initialize(parameters, options={})
|
7
|
+
@file = options[:file]
|
8
|
+
@base = options[:base]
|
9
|
+
|
10
|
+
super(parameters)
|
11
|
+
end
|
12
|
+
|
13
|
+
def load
|
14
|
+
if File.exists?(file)
|
15
|
+
values = YAML.load_file(file)
|
16
|
+
if base && values.has_key?(base)
|
17
|
+
@configuration = values[base]
|
18
|
+
else
|
19
|
+
@configuration = values
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Isomer::Base do
|
4
|
+
describe '.from' do
|
5
|
+
let(:klass) { Class.new(Isomer::Base) { |c| c.parameter :something } }
|
6
|
+
let(:source) { double('Source', load_and_validate: anything)}
|
7
|
+
|
8
|
+
it 'passes along the type, parameters, and options to the factory' do
|
9
|
+
parameter = double('Parameter', required?: false)
|
10
|
+
Isomer::Parameter.stub(:new).and_return(parameter)
|
11
|
+
|
12
|
+
Isomer::Sources.
|
13
|
+
should_receive(:factory).
|
14
|
+
with(:foo, [parameter], {bar: 'bar-option'}).
|
15
|
+
and_return(source)
|
16
|
+
|
17
|
+
klass.from(:foo, {bar: 'bar-option'})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.parameter' do
|
22
|
+
let(:klass) do
|
23
|
+
Class.new(Isomer::Base) do
|
24
|
+
parameter :the_value, default: 'foo', from: 'bar'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:instance) do
|
29
|
+
klass.from(:test, payload: {'the_value' => 'my-value'})
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'creates a method for the parameter' do
|
33
|
+
instance.respond_to?(:the_value).should == true
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'creates a new Parameter' do
|
37
|
+
parameter = Isomer::Parameter.new(:double, {})
|
38
|
+
Isomer::Parameter.should_receive(:new).
|
39
|
+
with(:the_value, {default: 'foo', from: 'bar'}).
|
40
|
+
and_return(parameter)
|
41
|
+
|
42
|
+
instance
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Isomer::Parameter do
|
4
|
+
describe '#default' do
|
5
|
+
it 'is set from the initializer' do
|
6
|
+
parameter = Isomer::Parameter.new(:foo, {default: 'my default'})
|
7
|
+
parameter.default.should == 'my default'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#name' do
|
12
|
+
context 'when there is no from option' do
|
13
|
+
it 'returns the id as a string' do
|
14
|
+
parameter = Isomer::Parameter.new(:foo, {})
|
15
|
+
parameter.name.should == 'foo'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when there is a from option' do
|
20
|
+
it 'returns the from value as a string' do
|
21
|
+
parameter = Isomer::Parameter.new(:bar, {from: :baz})
|
22
|
+
parameter.name.should == 'baz'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#required?' do
|
28
|
+
it 'returns true when required is set to true' do
|
29
|
+
parameter = Isomer::Parameter.new(anything, {required: true})
|
30
|
+
parameter.required?.should == true
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns false when required is set to anything other than true' do
|
34
|
+
parameter = Isomer::Parameter.new(anything, {required: 'blarg'})
|
35
|
+
parameter.required?.should == false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Isomer::Sources::Base do
|
4
|
+
describe '.new' do
|
5
|
+
it 'initalizes errors to an empty array' do
|
6
|
+
source = Isomer::Sources::Base.new(anything)
|
7
|
+
source.errors.should == []
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#load' do
|
12
|
+
it 'raises a NotImplementedError' do
|
13
|
+
source = Isomer::Sources::Base.new(anything)
|
14
|
+
expect {
|
15
|
+
source.load
|
16
|
+
}.to raise_error(NotImplementedError, "You must implement 'load' in Isomer::Sources::Base")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#validate' do
|
21
|
+
it 'raises an error for any required parameters not specified' do
|
22
|
+
parameter = Isomer::Parameter.new(:the_value, required: true)
|
23
|
+
source = Isomer::Sources::Test.new([parameter], payload: {})
|
24
|
+
source.load
|
25
|
+
|
26
|
+
expect { source.validate }.to raise_error Isomer::RequiredParameterError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#for' do
|
31
|
+
it 'returns the value for the parameter' do
|
32
|
+
parameter = double('Parameter', name: 'name')
|
33
|
+
source = Isomer::Sources::Test.new([parameter], payload: {'name' => 'value'})
|
34
|
+
source.load
|
35
|
+
|
36
|
+
source.for(parameter).should == 'value'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns the default if there is no configuration value' do
|
40
|
+
parameter = double('Parameter', name: 'name', default: 'bar')
|
41
|
+
source = Isomer::Sources::Test.new([parameter], payload: {})
|
42
|
+
source.load
|
43
|
+
|
44
|
+
source.for(parameter).should == 'bar'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Isomer::Sources::Environment do
|
4
|
+
let(:parameter) { double('Parameter', name: 'token') }
|
5
|
+
|
6
|
+
describe '#load' do
|
7
|
+
it 'looks up the parameters from the environment' do
|
8
|
+
source = Isomer::Sources::Environment.new([parameter])
|
9
|
+
|
10
|
+
ENV.should_receive(:[]).with('TOKEN')
|
11
|
+
source.load
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'stores all values in the configuration' do
|
15
|
+
source = Isomer::Sources::Environment.new([parameter])
|
16
|
+
|
17
|
+
ENV.stub(:[]).with('TOKEN').and_return('abcd-efgh')
|
18
|
+
source.load
|
19
|
+
source.configuration.should == {'token' => 'abcd-efgh'}
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with convert case off' do
|
23
|
+
it 'does not uppercase parameter names' do
|
24
|
+
source = Isomer::Sources::Environment.new([parameter], convert_case: false)
|
25
|
+
|
26
|
+
ENV.should_receive(:[]).with('token')
|
27
|
+
source.load
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with a prefix' do
|
32
|
+
it 'appends the prefix when looking up the environment variable' do
|
33
|
+
source = Isomer::Sources::Environment.new([parameter], prefix: 'APP_')
|
34
|
+
|
35
|
+
ENV.should_receive(:[]).with('APP_TOKEN')
|
36
|
+
source.load
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'respects the convert case flag' do
|
40
|
+
source = Isomer::Sources::Environment.new([parameter], convert_case: false, prefix: 'app_')
|
41
|
+
|
42
|
+
ENV.should_receive(:[]).with('app_token')
|
43
|
+
source.load
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Isomer::Sources::Yaml do
|
4
|
+
describe '#load' do
|
5
|
+
it 'loads the YAML file configuration file' do
|
6
|
+
File.stub(:exists?).and_return(true)
|
7
|
+
YAML.should_receive(:load_file).with('/home/configuration.yml').and_return({'foo' => 'bar'})
|
8
|
+
|
9
|
+
source = Isomer::Sources::Yaml.new(anything, file: '/home/configuration.yml')
|
10
|
+
source.load
|
11
|
+
|
12
|
+
source.configuration.should == {'foo' => 'bar'}
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'does not raise if the file does not exist' do
|
16
|
+
source = Isomer::Sources::Yaml.new(anything, file: '/home/configuration.yml')
|
17
|
+
expect { source.load }.to_not raise_error
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with a base' do
|
21
|
+
it 'returns the configuration under the base node' do
|
22
|
+
File.stub(:exists?).and_return(true)
|
23
|
+
YAML.stub(:load_file).and_return( 'production' => {'limit' => 100} )
|
24
|
+
|
25
|
+
source = Isomer::Sources::Yaml.new(anything, base: 'production')
|
26
|
+
source.load
|
27
|
+
|
28
|
+
source.configuration.should == {'limit' => 100}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Isomer::Sources do
|
4
|
+
describe '.factory' do
|
5
|
+
context 'with a source of :yaml' do
|
6
|
+
it 'uses the yaml source' do
|
7
|
+
Isomer::Sources::Yaml.
|
8
|
+
should_receive(:new).
|
9
|
+
with([], path: '/tmp/foo/bar.yml', base: 'development')
|
10
|
+
|
11
|
+
Isomer::Sources.factory(:yaml, [], path: '/tmp/foo/bar.yml', base: 'development')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with a source of :environment' do
|
16
|
+
it 'uses the environment source' do
|
17
|
+
Isomer::Sources::Environment.
|
18
|
+
should_receive(:new).
|
19
|
+
with([], prefix: 'APP_')
|
20
|
+
|
21
|
+
Isomer::Sources.factory(:environment, [], prefix: 'APP_')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with a source of :test' do
|
26
|
+
it 'uses the test source' do
|
27
|
+
Isomer::Sources::Test.
|
28
|
+
should_receive(:new).
|
29
|
+
with([], payload: {})
|
30
|
+
|
31
|
+
Isomer::Sources.factory(:test, [], payload: {})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/isomer_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Isomer do
|
4
|
+
describe '.configure' do
|
5
|
+
before do
|
6
|
+
Isomer::Base.stub(:from)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'yields the configuration to the class' do
|
10
|
+
expect do |b|
|
11
|
+
Isomer.configure(anything, {}, &b)
|
12
|
+
end.to yield_control
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'creates a new instance of the configuration class' do
|
16
|
+
klass = double('Anonymous Class')
|
17
|
+
Class.stub(:new).with(Isomer::Base).and_return(klass)
|
18
|
+
|
19
|
+
klass.should_receive(:from).with(:foo, :bar).and_return(:baz)
|
20
|
+
Isomer.configure(:foo, :bar).should == :baz
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
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
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'isomer'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: isomer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paul Guelpa
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: A general configuration solution
|
63
|
+
email:
|
64
|
+
- paul.guelpa@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- .travis.yml
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- isomer.gemspec
|
77
|
+
- lib/isomer.rb
|
78
|
+
- lib/isomer/base.rb
|
79
|
+
- lib/isomer/errors.rb
|
80
|
+
- lib/isomer/parameter.rb
|
81
|
+
- lib/isomer/sources.rb
|
82
|
+
- lib/isomer/sources/base.rb
|
83
|
+
- lib/isomer/sources/environment.rb
|
84
|
+
- lib/isomer/sources/test.rb
|
85
|
+
- lib/isomer/sources/yaml.rb
|
86
|
+
- lib/isomer/version.rb
|
87
|
+
- spec/isomer/base_spec.rb
|
88
|
+
- spec/isomer/parameter_spec.rb
|
89
|
+
- spec/isomer/sources/base_spec.rb
|
90
|
+
- spec/isomer/sources/environment_spec.rb
|
91
|
+
- spec/isomer/sources/yaml_spec.rb
|
92
|
+
- spec/isomer/sources_spec.rb
|
93
|
+
- spec/isomer_spec.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
homepage: ''
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
hash: -4134372492786935908
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
hash: -4134372492786935908
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.8.25
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: A general configuration solution
|
126
|
+
test_files:
|
127
|
+
- spec/isomer/base_spec.rb
|
128
|
+
- spec/isomer/parameter_spec.rb
|
129
|
+
- spec/isomer/sources/base_spec.rb
|
130
|
+
- spec/isomer/sources/environment_spec.rb
|
131
|
+
- spec/isomer/sources/yaml_spec.rb
|
132
|
+
- spec/isomer/sources_spec.rb
|
133
|
+
- spec/isomer_spec.rb
|
134
|
+
- spec/spec_helper.rb
|