static_config 0.0.2 → 0.0.3
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/.rspec +0 -1
- data/.travis.yml +5 -0
- data/Gemfile +2 -3
- data/Guardfile +9 -0
- data/MIT-LICENSE +20 -0
- data/README.md +2 -0
- data/Rakefile +2 -0
- data/lib/static_config/config_hash.rb +4 -7
- data/lib/static_config/version.rb +1 -1
- data/spec/static_config/aggregation/first_spec.rb +12 -0
- data/spec/static_config/aggregation/merge_spec.rb +12 -0
- data/spec/static_config/config_hash_spec.rb +2 -1
- data/spec/static_config/config_proxy_spec.rb +2 -1
- data/spec/static_config/reader/yaml_file_spec.rb +47 -7
- metadata +8 -19
- data/.autotest +0 -5
- data/spec/static_config/reader/yaml_file_spec.rb.empty +0 -0
- data/spec/static_config/reader/yaml_file_spec.rb.yml +0 -2
data/.rspec
CHANGED
data/Gemfile
CHANGED
data/Guardfile
ADDED
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2011 Matt Burke
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
data/Rakefile
CHANGED
|
@@ -5,14 +5,11 @@ module StaticConfig
|
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def method_missing(attr, *args)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
else
|
|
12
|
-
value
|
|
13
|
-
end
|
|
8
|
+
case value = @data[attr.to_s]
|
|
9
|
+
when Hash
|
|
10
|
+
ConfigHash.new value
|
|
14
11
|
else
|
|
15
|
-
|
|
12
|
+
value
|
|
16
13
|
end
|
|
17
14
|
end
|
|
18
15
|
|
|
@@ -35,4 +35,16 @@ describe StaticConfig::Aggregation::First do
|
|
|
35
35
|
let(:readers) { [reader_B, reader_A] }
|
|
36
36
|
its(:read) { should == {'b' => '1'} }
|
|
37
37
|
end
|
|
38
|
+
|
|
39
|
+
context 'with false in the first reader' do
|
|
40
|
+
let(:reader_with_false) { Reader.new('b' => false) }
|
|
41
|
+
context 'and an empty reader second' do
|
|
42
|
+
let(:readers) { [reader_with_false, empty_reader] }
|
|
43
|
+
its(:read) { should == {'b' => false} }
|
|
44
|
+
end
|
|
45
|
+
context 'and a value in the second reader' do
|
|
46
|
+
let(:readers) { [reader_with_false, reader_B] }
|
|
47
|
+
its(:read) { should == {'b' => false} }
|
|
48
|
+
end
|
|
49
|
+
end
|
|
38
50
|
end
|
|
@@ -36,4 +36,16 @@ describe StaticConfig::Aggregation::Merge do
|
|
|
36
36
|
let(:readers) { [deep_reader_A, deep_reader_B] }
|
|
37
37
|
its(:read) { should == {'really' => {'deep' => {'A' => '1', 'B' => '1'}}} }
|
|
38
38
|
end
|
|
39
|
+
|
|
40
|
+
context 'with false in the second reader' do
|
|
41
|
+
let(:reader_with_false) { Reader.new('b' => false) }
|
|
42
|
+
context 'and an empty reader first' do
|
|
43
|
+
let(:readers) { [Reader.new({}), reader_with_false] }
|
|
44
|
+
its(:read) { should == {'b' => false} }
|
|
45
|
+
end
|
|
46
|
+
context 'and a different value in the first reader' do
|
|
47
|
+
let(:readers) { [reader_B, reader_with_false] }
|
|
48
|
+
its(:read) { should == {'b' => false} }
|
|
49
|
+
end
|
|
50
|
+
end
|
|
39
51
|
end
|
|
@@ -2,10 +2,11 @@ require 'spec_helper'
|
|
|
2
2
|
require 'static_config/config_hash'
|
|
3
3
|
|
|
4
4
|
describe StaticConfig::ConfigHash do
|
|
5
|
-
let(:subject) { StaticConfig::ConfigHash.new({'a' => 'ok', 'nested' => { 'key' => 'also ok' }}) }
|
|
5
|
+
let(:subject) { StaticConfig::ConfigHash.new({'a' => 'ok', 'nested' => { 'key' => 'also ok' }, 'nottrue' => false}) }
|
|
6
6
|
|
|
7
7
|
its('a') { should == 'ok' }
|
|
8
8
|
its('nested') { should == { 'key' => 'also ok' } }
|
|
9
9
|
its('nested.key') { should == 'also ok' }
|
|
10
10
|
its('missing') { should be_nil }
|
|
11
|
+
its('nottrue') { should == false }
|
|
11
12
|
end
|
|
@@ -7,7 +7,7 @@ describe StaticConfig::ConfigProxy do
|
|
|
7
7
|
context do
|
|
8
8
|
class SimpleReader
|
|
9
9
|
def read
|
|
10
|
-
{'a' => 'ok', 'nested' => { 'key' => 'also ok' }}
|
|
10
|
+
{'a' => 'ok', 'nested' => { 'key' => 'also ok' }, 'nottrue' => false}
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
let(:reader) { SimpleReader.new }
|
|
@@ -16,6 +16,7 @@ describe StaticConfig::ConfigProxy do
|
|
|
16
16
|
its('nested') { should == { 'key' => 'also ok' } }
|
|
17
17
|
its('nested.key') { should == 'also ok' }
|
|
18
18
|
its('missing') { should be_nil }
|
|
19
|
+
its('nottrue') { should == false }
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
context do
|
|
@@ -1,34 +1,74 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require 'static_config/reader/yaml_file'
|
|
3
|
+
require 'tempfile'
|
|
3
4
|
|
|
4
5
|
describe StaticConfig::Reader::YamlFile do
|
|
5
6
|
let(:subject) { described_class.read(opts) }
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
let(:file) { Tempfile.new('static_config_specs').tap { |f| f.write(yaml) ; f.close } }
|
|
9
|
+
let(:base_opts) { { :file => file.path } }
|
|
10
|
+
|
|
11
|
+
let(:opts) { base_opts }
|
|
12
|
+
let(:yaml) { BASIC_YAML }
|
|
13
|
+
it('loads the yaml') { should == { 'key' => 'value' } }
|
|
9
14
|
|
|
10
15
|
context 'with section' do
|
|
11
|
-
|
|
16
|
+
let(:yaml) { YAML_WITH_DEV }
|
|
17
|
+
let(:opts) { base_opts.merge :section => 'dev' }
|
|
12
18
|
it('uses the section') { should == { 'key' => 'value' } }
|
|
13
19
|
end
|
|
14
20
|
|
|
15
21
|
context 'with a section that does not exist' do
|
|
16
|
-
|
|
22
|
+
let(:yaml) { YAML_WITH_DEV }
|
|
23
|
+
let(:opts) { base_opts.merge :section => 'notthere' }
|
|
17
24
|
it('is empty') { should == {} }
|
|
18
25
|
end
|
|
19
26
|
|
|
20
27
|
context 'with an empty file' do
|
|
21
|
-
|
|
28
|
+
let(:yaml) { '' }
|
|
22
29
|
it('is empty') { should == {} }
|
|
23
30
|
|
|
24
31
|
context 'and a section' do
|
|
25
|
-
|
|
32
|
+
let(:opts) { base_opts.merge :section => 'section' }
|
|
26
33
|
it('is empty') { should == {} }
|
|
27
34
|
end
|
|
28
35
|
end
|
|
29
36
|
|
|
30
37
|
context 'with a file that does not exist' do
|
|
31
|
-
|
|
38
|
+
let(:opts) { { :file => "/does/not/exist" } }
|
|
32
39
|
it('is empty') { should == {} }
|
|
33
40
|
end
|
|
41
|
+
|
|
42
|
+
context do
|
|
43
|
+
let(:yaml) { "x: #{yaml_value}" }
|
|
44
|
+
|
|
45
|
+
context 'string value' do
|
|
46
|
+
let(:yaml_value) { '123abc123' }
|
|
47
|
+
its(['x']) { should == '123abc123' }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context 'integer value' do
|
|
51
|
+
let(:yaml_value) { '123' }
|
|
52
|
+
its(['x']) { should == 123 }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context 'float value' do
|
|
56
|
+
let(:yaml_value) { '1.5' }
|
|
57
|
+
its(['x']) { should == 1.5 }
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
context 'false value' do
|
|
61
|
+
let(:yaml_value) { 'false' }
|
|
62
|
+
its(['x']) { should == false }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
BASIC_YAML = <<END_BASIC_YAML
|
|
67
|
+
key: value
|
|
68
|
+
END_BASIC_YAML
|
|
69
|
+
|
|
70
|
+
YAML_WITH_DEV = <<END_YAML_WITH_DEV
|
|
71
|
+
dev:
|
|
72
|
+
key: value
|
|
73
|
+
END_YAML_WITH_DEV
|
|
34
74
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: static_config
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash: 27
|
|
5
4
|
prerelease:
|
|
6
|
-
|
|
7
|
-
- 0
|
|
8
|
-
- 0
|
|
9
|
-
- 2
|
|
10
|
-
version: 0.0.2
|
|
5
|
+
version: 0.0.3
|
|
11
6
|
platform: ruby
|
|
12
7
|
authors:
|
|
13
8
|
- Matt Burke
|
|
@@ -15,7 +10,8 @@ autorequire:
|
|
|
15
10
|
bindir: bin
|
|
16
11
|
cert_chain: []
|
|
17
12
|
|
|
18
|
-
date: 2011-
|
|
13
|
+
date: 2011-11-18 00:00:00 -05:00
|
|
14
|
+
default_executable:
|
|
19
15
|
dependencies: []
|
|
20
16
|
|
|
21
17
|
description: Load configuration from yaml and/or environment variables
|
|
@@ -28,10 +24,12 @@ extensions: []
|
|
|
28
24
|
extra_rdoc_files: []
|
|
29
25
|
|
|
30
26
|
files:
|
|
31
|
-
- .autotest
|
|
32
27
|
- .gitignore
|
|
33
28
|
- .rspec
|
|
29
|
+
- .travis.yml
|
|
34
30
|
- Gemfile
|
|
31
|
+
- Guardfile
|
|
32
|
+
- MIT-LICENSE
|
|
35
33
|
- README.md
|
|
36
34
|
- Rakefile
|
|
37
35
|
- lib/static_config.rb
|
|
@@ -53,9 +51,8 @@ files:
|
|
|
53
51
|
- spec/static_config/reader/environment_spec.rb
|
|
54
52
|
- spec/static_config/reader/yaml_env_spec.rb
|
|
55
53
|
- spec/static_config/reader/yaml_file_spec.rb
|
|
56
|
-
- spec/static_config/reader/yaml_file_spec.rb.empty
|
|
57
|
-
- spec/static_config/reader/yaml_file_spec.rb.yml
|
|
58
54
|
- static_config.gemspec
|
|
55
|
+
has_rdoc: true
|
|
59
56
|
homepage: http://github.com/spraints/static_config
|
|
60
57
|
licenses: []
|
|
61
58
|
|
|
@@ -69,23 +66,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
69
66
|
requirements:
|
|
70
67
|
- - ">="
|
|
71
68
|
- !ruby/object:Gem::Version
|
|
72
|
-
hash: 3
|
|
73
|
-
segments:
|
|
74
|
-
- 0
|
|
75
69
|
version: "0"
|
|
76
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
71
|
none: false
|
|
78
72
|
requirements:
|
|
79
73
|
- - ">="
|
|
80
74
|
- !ruby/object:Gem::Version
|
|
81
|
-
hash: 3
|
|
82
|
-
segments:
|
|
83
|
-
- 0
|
|
84
75
|
version: "0"
|
|
85
76
|
requirements: []
|
|
86
77
|
|
|
87
78
|
rubyforge_project: static_config
|
|
88
|
-
rubygems_version: 1.
|
|
79
|
+
rubygems_version: 1.6.2
|
|
89
80
|
signing_key:
|
|
90
81
|
specification_version: 3
|
|
91
82
|
summary: Load configuration from yaml and/or environment variables
|
|
@@ -98,5 +89,3 @@ test_files:
|
|
|
98
89
|
- spec/static_config/reader/environment_spec.rb
|
|
99
90
|
- spec/static_config/reader/yaml_env_spec.rb
|
|
100
91
|
- spec/static_config/reader/yaml_file_spec.rb
|
|
101
|
-
- spec/static_config/reader/yaml_file_spec.rb.empty
|
|
102
|
-
- spec/static_config/reader/yaml_file_spec.rb.yml
|
data/.autotest
DELETED
|
File without changes
|