app_conf 0.2.1 → 0.2.2
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/app_conf.gemspec +1 -1
- data/lib/app_conf.rb +1 -2
- data/spec/app_conf_spec.rb +71 -65
- metadata +2 -2
data/app_conf.gemspec
CHANGED
|
@@ -2,7 +2,7 @@ require 'base64'
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = 'app_conf'
|
|
5
|
-
s.version = '0.2.
|
|
5
|
+
s.version = '0.2.2'
|
|
6
6
|
s.authors = 'Phil Thompson'
|
|
7
7
|
s.email = Base64.decode64("cGhpbEBlbGVjdHJpY3Zpc2lvbnMuY29t\n")
|
|
8
8
|
s.summary = 'Simplest YAML Backed Application Wide Configuration (AppConfig)'
|
data/lib/app_conf.rb
CHANGED
data/spec/app_conf_spec.rb
CHANGED
|
@@ -3,89 +3,95 @@ require 'minitest/autorun'
|
|
|
3
3
|
require 'app_conf'
|
|
4
4
|
|
|
5
5
|
describe AppConf do
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
AppConf.clear
|
|
9
|
-
AppConf.load("#{@dir}/config.yml")
|
|
6
|
+
it 'returns nil on empty tree' do
|
|
7
|
+
AppConf.user.must_be_nil
|
|
10
8
|
end
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
it 'works with dot notation' do
|
|
19
|
-
AppConf.fullname.must_equal 'Joe Bloggs'
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'works with hash notation' do
|
|
23
|
-
AppConf[:fullname].must_equal 'Joe Bloggs'
|
|
24
|
-
AppConf['fullname'].must_equal 'Joe Bloggs'
|
|
25
|
-
end
|
|
10
|
+
describe 'General' do
|
|
11
|
+
before(:each) do
|
|
12
|
+
@dir = File.dirname(__FILE__)
|
|
13
|
+
AppConf.clear
|
|
14
|
+
AppConf.load("#{@dir}/config.yml")
|
|
15
|
+
end
|
|
26
16
|
|
|
27
|
-
|
|
28
|
-
it 'clears all keys' do
|
|
29
|
-
AppConf.fullname.wont_be_nil
|
|
17
|
+
it 'creates from a hash' do
|
|
30
18
|
AppConf.clear
|
|
31
|
-
AppConf.
|
|
19
|
+
AppConf.from_hash({:user => {:name => {:first => 'Joe'}}})
|
|
20
|
+
AppConf.user.name.first.must_equal 'Joe'
|
|
32
21
|
end
|
|
33
22
|
|
|
34
|
-
it '
|
|
35
|
-
AppConf.
|
|
23
|
+
it 'works with dot notation' do
|
|
24
|
+
AppConf.fullname.must_equal 'Joe Bloggs'
|
|
36
25
|
end
|
|
37
|
-
end
|
|
38
26
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
27
|
+
it 'works with hash notation' do
|
|
28
|
+
AppConf[:fullname].must_equal 'Joe Bloggs'
|
|
29
|
+
AppConf['fullname'].must_equal 'Joe Bloggs'
|
|
30
|
+
end
|
|
42
31
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
32
|
+
describe 'clear' do
|
|
33
|
+
it 'clears all keys' do
|
|
34
|
+
AppConf.fullname.wont_be_nil
|
|
35
|
+
AppConf.clear
|
|
36
|
+
AppConf.fullname.must_be_nil
|
|
37
|
+
end
|
|
47
38
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
it 'does not return AppConf instance' do
|
|
40
|
+
AppConf.clear.must_be_nil
|
|
41
|
+
end
|
|
42
|
+
end
|
|
52
43
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
AppConf.user.address.street.must_equal '1 Some Road'
|
|
57
|
-
AppConf.user.name.first.must_equal 'Joe'
|
|
58
|
-
end
|
|
44
|
+
it 'works with nested dot notation' do
|
|
45
|
+
AppConf.user.name.first.must_equal 'Joe'
|
|
46
|
+
end
|
|
59
47
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
end
|
|
48
|
+
it 'works with nested hash notation' do
|
|
49
|
+
AppConf[:user][:name][:first].must_equal 'Joe'
|
|
50
|
+
AppConf['user']['name']['first'].must_equal 'Joe'
|
|
51
|
+
end
|
|
65
52
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
53
|
+
it 'works with mixed notation' do
|
|
54
|
+
AppConf[:user][:name][:first].must_equal 'Joe'
|
|
55
|
+
AppConf.user['name'].first.must_equal 'Joe'
|
|
56
|
+
end
|
|
70
57
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
58
|
+
it 'works with multiple files' do
|
|
59
|
+
AppConf.clear
|
|
60
|
+
AppConf.load("#{@dir}/config.yml", "#{@dir}/other.yml")
|
|
61
|
+
AppConf.user.address.street.must_equal '1 Some Road'
|
|
62
|
+
AppConf.user.name.first.must_equal 'Joe'
|
|
63
|
+
end
|
|
75
64
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
65
|
+
it 'loads additional files' do
|
|
66
|
+
AppConf.load("#{@dir}/other.yml")
|
|
67
|
+
AppConf.user.address.street.must_equal '1 Some Road'
|
|
68
|
+
AppConf.user.name.first.must_equal 'Joe'
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'allows additional keys to be set' do
|
|
72
|
+
AppConf.user.name.last = 'Bloggs'
|
|
73
|
+
AppConf.user.name.last.must_equal 'Bloggs'
|
|
74
|
+
end
|
|
80
75
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
AppConf.
|
|
76
|
+
it 'allows additional keys to be set with hash notation' do
|
|
77
|
+
AppConf.user[:name][:last] = 'Bloggs'
|
|
78
|
+
AppConf.user.name.last.must_equal 'Bloggs'
|
|
84
79
|
end
|
|
85
80
|
|
|
86
|
-
it '
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
it 'allows existing keys to be overridden' do
|
|
82
|
+
AppConf.user.name.first = 'Jody'
|
|
83
|
+
AppConf.user.name.first.must_equal 'Jody'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe 'limitations' do
|
|
87
|
+
it 'returns nil when unknown key specified' do
|
|
88
|
+
AppConf.unknown.must_be_nil
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'does not allow nested items to be overwritten' do
|
|
92
|
+
lambda { AppConf.user.name = 'something' }.must_raise RuntimeError
|
|
93
|
+
lambda { AppConf[:user][:name] = 'something' }.must_raise RuntimeError
|
|
94
|
+
end
|
|
89
95
|
end
|
|
90
96
|
end
|
|
91
97
|
end
|