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 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.1'
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
@@ -1,11 +1,10 @@
1
1
  require 'yaml'
2
2
 
3
3
  class AppConf
4
- @@root = new
5
-
6
4
  def initialize
7
5
  @hash = {}
8
6
  end
7
+ @@root = new
9
8
 
10
9
  def self.load(*filenames)
11
10
  filenames.each do |filename|
@@ -3,89 +3,95 @@ require 'minitest/autorun'
3
3
  require 'app_conf'
4
4
 
5
5
  describe AppConf do
6
- before(:each) do
7
- @dir = File.dirname(__FILE__)
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
- it 'creates from a hash' do
13
- AppConf.clear
14
- AppConf.from_hash({:user => {:name => {:first => 'Joe'}}})
15
- AppConf.user.name.first.must_equal 'Joe'
16
- end
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
- describe 'clear' do
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.fullname.must_be_nil
19
+ AppConf.from_hash({:user => {:name => {:first => 'Joe'}}})
20
+ AppConf.user.name.first.must_equal 'Joe'
32
21
  end
33
22
 
34
- it 'does not return AppConf instance' do
35
- AppConf.clear.must_be_nil
23
+ it 'works with dot notation' do
24
+ AppConf.fullname.must_equal 'Joe Bloggs'
36
25
  end
37
- end
38
26
 
39
- it 'works with nested dot notation' do
40
- AppConf.user.name.first.must_equal 'Joe'
41
- end
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
- it 'works with nested hash notation' do
44
- AppConf[:user][:name][:first].must_equal 'Joe'
45
- AppConf['user']['name']['first'].must_equal 'Joe'
46
- end
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
- it 'works with mixed notation' do
49
- AppConf[:user][:name][:first].must_equal 'Joe'
50
- AppConf.user['name'].first.must_equal 'Joe'
51
- end
39
+ it 'does not return AppConf instance' do
40
+ AppConf.clear.must_be_nil
41
+ end
42
+ end
52
43
 
53
- it 'works with multiple files' do
54
- AppConf.clear
55
- AppConf.load("#{@dir}/config.yml", "#{@dir}/other.yml")
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
- it 'loads additional files' do
61
- AppConf.load("#{@dir}/other.yml")
62
- AppConf.user.address.street.must_equal '1 Some Road'
63
- AppConf.user.name.first.must_equal 'Joe'
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
- it 'allows additional keys to be set' do
67
- AppConf.user.name.last = 'Bloggs'
68
- AppConf.user.name.last.must_equal 'Bloggs'
69
- end
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
- it 'allows additional keys to be set with hash notation' do
72
- AppConf.user[:name][:last] = 'Bloggs'
73
- AppConf.user.name.last.must_equal 'Bloggs'
74
- end
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
- it 'allows existing keys to be overridden' do
77
- AppConf.user.name.first = 'Jody'
78
- AppConf.user.name.first.must_equal 'Jody'
79
- end
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
- describe 'limitations' do
82
- it 'returns nil when unknown key specified' do
83
- AppConf.unknown.must_be_nil
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 'does not allow nested items to be overwritten' do
87
- lambda { AppConf.user.name = 'something' }.must_raise RuntimeError
88
- lambda { AppConf[:user][:name] = 'something' }.must_raise RuntimeError
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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Phil Thompson