basic_config 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -3
- data/Rakefile +6 -0
- data/basic_config.gemspec +3 -3
- data/spec/basic_config_spec.rb +27 -13
- metadata +5 -5
data/README.md
CHANGED
@@ -84,11 +84,13 @@ if you're constructing BasicConfig with `new`, then it'll show source code
|
|
84
84
|
location where BasicConfig is initialized.
|
85
85
|
|
86
86
|
```ruby
|
87
|
+
# Let's say this is config.rb, line 7:
|
87
88
|
AppConfig = BasicConfig.new({ secret_token: 'something' })
|
88
|
-
secret_token = AppConfig.secret_toklen # Note a typo here
|
89
89
|
|
90
|
-
#
|
91
|
-
|
90
|
+
# And this is somewhere in some method in another file:
|
91
|
+
secret_token = AppConfig.secret_toklen # Note a typo here
|
92
|
+
# Above line will result in BasicConfig::NotFound exception with message:
|
93
|
+
# Configuration key 'secret_toklen' is missing in BasicConfig constructed at config.rb:7 in `method'
|
92
94
|
```
|
93
95
|
|
94
96
|
*Note:* There is also an `include?` method which you can use to check if
|
data/Rakefile
CHANGED
data/basic_config.gemspec
CHANGED
@@ -3,16 +3,16 @@ require File.expand_path('../lib/basic_config', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ['Stepan Tubanov']
|
6
|
-
gem.email = ['
|
6
|
+
gem.email = ['stepan@tubanov.com']
|
7
7
|
gem.description = 'Makes it easier to use configuration by wrapping it in a struct-like object'
|
8
8
|
gem.summary = 'Friendly configuration wrapper'
|
9
|
-
gem.homepage = 'https://github.com/
|
9
|
+
gem.homepage = 'https://github.com/stepantubanov/basic_config'
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
12
|
gem.test_files = gem.files.grep(%r{^(spec)/})
|
13
13
|
gem.name = 'basic_config'
|
14
14
|
gem.require_path = 'lib'
|
15
|
-
gem.version = '0.1.
|
15
|
+
gem.version = '0.1.1'
|
16
16
|
|
17
17
|
gem.add_development_dependency('rspec', '~> 2.10')
|
18
18
|
end
|
data/spec/basic_config_spec.rb
CHANGED
@@ -6,16 +6,22 @@ describe BasicConfig do
|
|
6
6
|
'one' => 'something',
|
7
7
|
'two' => 'other_value',
|
8
8
|
'three' => {
|
9
|
-
'nested' => '123'
|
9
|
+
'nested' => '123',
|
10
|
+
'more' => {
|
11
|
+
'param' => 'value'
|
12
|
+
}
|
10
13
|
}
|
11
14
|
}
|
12
15
|
end
|
13
16
|
let(:symbolized_hash) do
|
14
17
|
{
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
18
|
+
one: 'something',
|
19
|
+
two: 'other_value',
|
20
|
+
three: {
|
21
|
+
nested: '123',
|
22
|
+
more: {
|
23
|
+
param: 'value'
|
24
|
+
}
|
19
25
|
}
|
20
26
|
}
|
21
27
|
end
|
@@ -45,7 +51,7 @@ describe BasicConfig do
|
|
45
51
|
should respond_to :three
|
46
52
|
should_not respond_to :unknown
|
47
53
|
end
|
48
|
-
|
54
|
+
|
49
55
|
it 'raises BasicConfig::KeyNotFound for unknown keys' do
|
50
56
|
expect { subject.four }.to raise_error(BasicConfig::NotFound)
|
51
57
|
end
|
@@ -81,7 +87,7 @@ describe BasicConfig do
|
|
81
87
|
BasicConfig.load_env('file', environment).to_hash.should == expected_result
|
82
88
|
end
|
83
89
|
end
|
84
|
-
|
90
|
+
|
85
91
|
describe BasicConfig::NotFound do
|
86
92
|
let(:exception) do
|
87
93
|
begin
|
@@ -93,6 +99,7 @@ describe BasicConfig do
|
|
93
99
|
subject { exception.message }
|
94
100
|
let(:original_config) { BasicConfig.new(hash) }
|
95
101
|
let(:original_scoping) { '' }
|
102
|
+
let(:scoped_missing_key_name) { original_scoping + missing_key_name }
|
96
103
|
|
97
104
|
shared_examples_for 'specific failure' do
|
98
105
|
it 'contains the right location' do
|
@@ -100,15 +107,15 @@ describe BasicConfig do
|
|
100
107
|
end
|
101
108
|
|
102
109
|
it 'contains the right key' do
|
103
|
-
should include "'#{
|
110
|
+
should include "'#{scoped_missing_key_name}'"
|
104
111
|
end
|
105
112
|
end
|
106
113
|
|
107
114
|
shared_examples_for 'construction contexts' do
|
108
115
|
context 'when constructed manually' do
|
109
116
|
let(:original_config) { BasicConfig.new(hash) }
|
110
|
-
let(:location) { 'spec/basic_config_spec.rb:
|
111
|
-
|
117
|
+
let(:location) { 'spec/basic_config_spec.rb:116' }
|
118
|
+
|
112
119
|
it_behaves_like 'specific failure'
|
113
120
|
end
|
114
121
|
|
@@ -116,7 +123,7 @@ describe BasicConfig do
|
|
116
123
|
let(:content) { hash }
|
117
124
|
let(:filename) { 'example.yml' }
|
118
125
|
let(:location) { filename }
|
119
|
-
|
126
|
+
|
120
127
|
before do
|
121
128
|
YAML.stub(:load_file).with(filename).and_return(content)
|
122
129
|
end
|
@@ -143,14 +150,21 @@ describe BasicConfig do
|
|
143
150
|
|
144
151
|
context 'top-level' do
|
145
152
|
let(:config) { original_config }
|
146
|
-
let(:missing_key_name) {
|
153
|
+
let(:missing_key_name) { 'missing_key' }
|
147
154
|
|
148
155
|
it_behaves_like 'construction contexts'
|
149
156
|
end
|
150
157
|
|
151
158
|
context 'one-level in' do
|
152
159
|
let(:config) { original_config.three }
|
153
|
-
let(:missing_key_name) {
|
160
|
+
let(:missing_key_name) { 'three.missing_key' }
|
161
|
+
|
162
|
+
it_behaves_like 'construction contexts'
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'two-levels in' do
|
166
|
+
let(:config) { original_config.three.more }
|
167
|
+
let(:missing_key_name) { 'three.more.missing_key' }
|
154
168
|
|
155
169
|
it_behaves_like 'construction contexts'
|
156
170
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basic_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
description: Makes it easier to use configuration by wrapping it in a struct-like
|
31
31
|
object
|
32
32
|
email:
|
33
|
-
-
|
33
|
+
- stepan@tubanov.com
|
34
34
|
executables: []
|
35
35
|
extensions: []
|
36
36
|
extra_rdoc_files: []
|
@@ -44,7 +44,7 @@ files:
|
|
44
44
|
- basic_config.gemspec
|
45
45
|
- lib/basic_config.rb
|
46
46
|
- spec/basic_config_spec.rb
|
47
|
-
homepage: https://github.com/
|
47
|
+
homepage: https://github.com/stepantubanov/basic_config
|
48
48
|
licenses: []
|
49
49
|
post_install_message:
|
50
50
|
rdoc_options: []
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.8.
|
67
|
+
rubygems_version: 1.8.23
|
68
68
|
signing_key:
|
69
69
|
specification_version: 3
|
70
70
|
summary: Friendly configuration wrapper
|