configatron 3.2.0 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +2 -2
  3. data/History.txt +72 -0
  4. data/README.md +25 -24
  5. data/Rakefile +10 -4
  6. data/configatron.gemspec +1 -0
  7. data/lib/configatron.rb +22 -4
  8. data/lib/configatron/core.rb +6 -6
  9. data/lib/configatron/ext/kernel.rb +5 -0
  10. data/lib/configatron/integrations.rb +4 -0
  11. data/lib/configatron/integrations/minitest.rb +29 -0
  12. data/lib/configatron/{rails.rb → integrations/rails.rb} +1 -1
  13. data/lib/configatron/root_store.rb +121 -0
  14. data/lib/configatron/store.rb +100 -63
  15. data/lib/configatron/version.rb +1 -1
  16. data/lib/generators/configatron/install/templates/configatron/defaults.rb +2 -2
  17. data/lib/generators/configatron/install/templates/configatron/development.rb +2 -2
  18. data/lib/generators/configatron/install/templates/configatron/production.rb +2 -2
  19. data/lib/generators/configatron/install/templates/configatron/test.rb +2 -2
  20. data/lib/generators/configatron/install/templates/initializers/configatron.rb +1 -1
  21. data/test/_lib.rb +17 -0
  22. data/test/functional/_lib.rb +10 -0
  23. data/test/functional/_lib/scripts/core.rb +11 -0
  24. data/test/functional/configatron.rb +165 -0
  25. data/test/functional/delayed.rb +18 -0
  26. data/test/functional/loading.rb +10 -0
  27. data/test/functional/minitest.rb +18 -0
  28. data/test/unit/_lib.rb +10 -0
  29. data/test/unit/configatron/proc.rb +24 -0
  30. data/test/unit/configatron/root_store.rb +37 -0
  31. data/test/unit/configatron/store.rb +149 -0
  32. metadata +73 -30
  33. checksums.yaml +0 -7
  34. data/.ruby-version +0 -1
  35. data/lib/configatron/deep_clone.rb +0 -69
  36. data/lib/configatron/kernel.rb +0 -21
  37. data/test/configatron/kernel_test.rb +0 -24
  38. data/test/configatron/proc_test.rb +0 -27
  39. data/test/configatron/store_test.rb +0 -256
  40. data/test/configatron_test.rb +0 -5
  41. data/test/test_helper.rb +0 -15
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 1dc9cfe0ed3b4c2c0c90b325d4b837e4aed30d8b
4
- data.tar.gz: 6bd11604cc4abf42aa461f33970e0935580774a7
5
- SHA512:
6
- metadata.gz: 8f4c42d22a0fa92b539c716aa2fcb53e3b837cf843f6fde91114823d8a5f2eb9c022d1712af686fadab9a3d1604ae746f2f64d626d4c4fa298b9d192f6e18823
7
- data.tar.gz: 6ba36b1929bf8fad1774f10c309b145f3cddd01371a2d2b81213dc92f3d7446a03d18255425c8ffbf48649100c3535e54dfa39a080e37ad8f9200c60be7125cc
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.1.0
@@ -1,69 +0,0 @@
1
- module DeepClone
2
- # = DeepClone
3
- #
4
- # == Version
5
- # 1.2006.05.23 (change of the first number means Big Change)
6
- #
7
- # == Description
8
- # Adds deep_clone method to an object which produces deep copy of it. It means
9
- # if you clone a Hash, every nested items and their nested items will be cloned.
10
- # Moreover deep_clone checks if the object is already cloned to prevent endless recursion.
11
- #
12
- # == Usage
13
- #
14
- # (see examples directory under the ruby gems root directory)
15
- #
16
- # require 'rubygems'
17
- # require 'deep_clone'
18
- #
19
- # include DeepClone
20
- #
21
- # obj = []
22
- # a = [ true, false, obj ]
23
- # b = a.deep_clone
24
- # obj.push( 'foo' )
25
- # p obj # >> [ 'foo' ]
26
- # p b[2] # >> []
27
- #
28
- # == Source
29
- # http://simplypowerful.1984.cz/goodlibs/1.2006.05.23
30
- #
31
- # == Author
32
- # jan molic (/mig/at_sign/1984/dot/cz/)
33
- #
34
- # == Licence
35
- # You can redistribute it and/or modify it under the same terms of Ruby's license;
36
- # either the dual license version in 2003, or any later version.
37
- #
38
- def deep_clone( obj=self, cloned={} )
39
- if cloned.has_key?( obj.object_id )
40
- return cloned[obj.object_id]
41
- else
42
- begin
43
- cl = obj.clone
44
- rescue Exception
45
- # unclonnable (TrueClass, Fixnum, ...)
46
- cloned[obj.object_id] = obj
47
- return obj
48
- else
49
- cloned[obj.object_id] = cl
50
- cloned[cl.object_id] = cl
51
- if cl.is_a?( Hash )
52
- cl.clone.each { |k,v|
53
- cl[k] = deep_clone( v, cloned )
54
- }
55
- elsif cl.is_a?( Array )
56
- cl.collect! { |v|
57
- deep_clone( v, cloned )
58
- }
59
- end
60
- cl.instance_variables.each do |var|
61
- v = cl.instance_eval( var.to_s )
62
- v_cl = deep_clone( v, cloned )
63
- cl.instance_eval( "#{var} = v_cl" )
64
- end
65
- return cl
66
- end
67
- end
68
- end
69
- end
@@ -1,21 +0,0 @@
1
- require 'singleton'
2
- class Configatron::KernelStore < BasicObject
3
- include ::Singleton
4
-
5
- attr_reader :store
6
-
7
- def initialize
8
- @store = ::Configatron::Store.new
9
- end
10
-
11
- def method_missing(name, *args, &block)
12
- store.send(name, *args, &block)
13
- end
14
-
15
- end
16
-
17
- module Kernel
18
- def configatron
19
- Configatron::KernelStore.instance
20
- end
21
- end
@@ -1,24 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe Configatron::KernelStore do
4
-
5
- let(:store) { Configatron::KernelStore.instance }
6
-
7
- it 'passes on to Configatron::Store' do
8
- configatron.a.b.c.d = 'D'
9
- configatron.a.b.c.d.must_equal 'D'
10
- end
11
-
12
- end
13
-
14
- describe Kernel do
15
-
16
- describe 'configatron' do
17
-
18
- it 'returns an instance of Configatron::Store' do
19
- configatron.kind_of?(Configatron::Store).must_equal true
20
- end
21
-
22
- end
23
-
24
- end
@@ -1,27 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe Configatron::Proc do
4
-
5
- let(:store) { Configatron::Store.new }
6
- let(:proc) { Configatron::Proc.new {rand} }
7
-
8
- describe '#call' do
9
-
10
- it 'executes the block and returns the results' do
11
- stubs(:rand).returns(4)
12
- proc.call.must_equal 4
13
- end
14
-
15
- it 'caches the result if finalize? return true' do
16
- proc.stubs(:finalize?).returns(true)
17
- proc.call.must_equal proc.call
18
- end
19
-
20
- it 'does not cache the result if finalize? returns false' do
21
- proc.stubs(:finalize?).returns(false)
22
- proc.call.wont_equal proc.call
23
- end
24
-
25
- end
26
-
27
- end
@@ -1,256 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe Configatron::Store do
4
-
5
- let(:store) { Configatron::Store.new }
6
-
7
- context "[]" do
8
-
9
- let(:store) { Configatron::Store.new(foo: "bar") }
10
-
11
- it "returns the value if there is one" do
12
- store[:foo].must_equal "bar"
13
- store["foo"].must_equal "bar"
14
- end
15
-
16
- it "returns a new Configatron::Store object if there is no value" do
17
- store[:unknown].must_be_kind_of Configatron::Store
18
- store["unknown"].must_be_kind_of Configatron::Store
19
- end
20
-
21
- context 'Configatron::Proc' do
22
-
23
- it 'executes the proc' do
24
- store.a = Configatron::Proc.new {1+1}
25
- store.a.must_equal 2
26
- end
27
-
28
- end
29
-
30
- end
31
-
32
- context "[]=" do
33
-
34
- it "sets the value" do
35
- store[:foo] = "bar"
36
- store[:foo].must_equal "bar"
37
- store["foo"].must_equal "bar"
38
-
39
- store[:baz] = "bazzy"
40
- store[:baz].must_equal "bazzy"
41
- store["baz"].must_equal "bazzy"
42
- end
43
-
44
- end
45
-
46
- context "fetch" do
47
-
48
- let(:store) { Configatron::Store.new(foo: "bar") }
49
-
50
- it "returns the value" do
51
- store.fetch(:foo).must_equal "bar"
52
- store.fetch("foo").must_equal "bar"
53
- end
54
-
55
- it "sets and returns the value of the default_value if no value is found" do
56
- store.fetch(:bar, "bar!!").must_equal "bar!!"
57
- store.bar.must_equal "bar!!"
58
- end
59
-
60
- it "sets and returns the value of the block if no value is found" do
61
- store.fetch(:bar) do
62
- "bar!"
63
- end.must_equal "bar!"
64
- store.bar.must_equal "bar!"
65
- end
66
-
67
- end
68
-
69
- context "nil?" do
70
-
71
- it "returns true if there is no value set" do
72
- store.foo.must_be_nil
73
- store.foo = "bar"
74
- store.foo.wont_be_nil
75
- end
76
-
77
- end
78
-
79
- context "empty?" do
80
-
81
- it "returns true if there is no value set" do
82
- store.foo.must_be_empty
83
- store.foo = "bar"
84
- store.foo.wont_be_empty
85
- end
86
-
87
- end
88
-
89
- context "key?" do
90
-
91
- it "returns true if there is a key" do
92
- store.key?(:foo).must_equal false
93
- store.foo = "bar"
94
- store.key?(:foo).must_equal true
95
- end
96
-
97
- it "returns false if the key is a Configatron::Store" do
98
- store.key?(:foo).must_equal false
99
- store.foo = Configatron::Store.new
100
- store.key?(:foo).must_equal false
101
- end
102
-
103
- end
104
-
105
- context "has_key?" do
106
-
107
- it "returns true if there is a key" do
108
- store.has_key?(:foo).must_equal false
109
- store.foo = "bar"
110
- store.has_key?(:foo).must_equal true
111
- end
112
-
113
- it "returns false if the key is a Configatron::Store" do
114
- store.has_key?(:foo).must_equal false
115
- store.foo = Configatron::Store.new
116
- store.has_key?(:foo).must_equal false
117
- end
118
-
119
- end
120
-
121
- context "method_missing" do
122
-
123
- let(:store) { Configatron::Store.new(foo: "bar") }
124
-
125
- it "returns the value if there is one" do
126
- store.foo.must_equal "bar"
127
- end
128
-
129
- it "returns a Configatron::Store if there is no value" do
130
- store.bar.must_be_kind_of Configatron::Store
131
- end
132
-
133
- it "works with deeply nested values" do
134
- store.a.b.c.d = "DD"
135
- store.a.b.c.d.must_equal "DD"
136
- end
137
-
138
- context 'with bang' do
139
-
140
- it "raises an exception if the key doesn't exist" do
141
- lambda {store.a.b!}.must_raise Configatron::UndefinedKeyError
142
- end
143
-
144
- it "returns the value" do
145
- store.a.b = 'B'
146
- store.a.b!.must_equal 'B'
147
- end
148
-
149
- end
150
-
151
- end
152
-
153
- context "lock!" do
154
-
155
- before do
156
- store.a.b.c.d = 'DD'
157
- store.lock!
158
- end
159
-
160
- it "raises an error when accessing non-existing values" do
161
- store.a.wont_be_nil
162
- store.a.b.wont_be_nil
163
- store.a.b.c.wont_be_nil
164
- store.a.b.c.d.must_equal "DD"
165
- proc {store.unknown}.must_raise(Configatron::UndefinedKeyError)
166
- end
167
-
168
- it "raises an error when trying to set a non-existing key" do
169
- proc {store.unknown = "known"}.must_raise(Configatron::LockedError)
170
- end
171
-
172
- end
173
-
174
- context "temp" do
175
-
176
- before do
177
- store.a = 'A'
178
- store.b = 'B'
179
- end
180
-
181
- it "allows for temporary setting of values" do
182
- store.a.must_equal 'A'
183
- store.b.must_equal 'B'
184
- store.temp do
185
- store.a = 'AA'
186
- store.c = 'C'
187
- store.a.must_equal 'AA'
188
- store.b.must_equal 'B'
189
- store.c.must_equal 'C'
190
- end
191
- store.a.must_equal 'A'
192
- store.b.must_equal 'B'
193
- store.c.must_be_nil
194
- end
195
-
196
- context "start/end" do
197
-
198
- it "allows for temporary setting of values" do
199
- store.a.must_equal 'A'
200
- store.b.must_equal 'B'
201
- store.temp_start
202
- store.a = 'AA'
203
- store.c = 'C'
204
- store.a.must_equal 'AA'
205
- store.b.must_equal 'B'
206
- store.c.must_equal 'C'
207
- store.temp_end
208
- store.a.must_equal 'A'
209
- store.b.must_equal 'B'
210
- store.c.must_be_nil
211
- end
212
-
213
- end
214
-
215
- end
216
-
217
- context "configuring" do
218
-
219
- context "configure_from_hash" do
220
-
221
- it "allows setup from a hash" do
222
- store.configure_from_hash(one: 1, a: {b: {c: {d: "DD"}}})
223
- store.one.must_equal 1
224
- store.a.b.c.d.must_equal "DD"
225
- end
226
-
227
- end
228
-
229
- context "with a block" do
230
-
231
- before do
232
- store.a.b = 'B'
233
- end
234
-
235
- it "yields up the store to configure with" do
236
- store.a do |a|
237
- a.c = 'CC'
238
- end
239
- store.a.b.must_equal 'B'
240
- store.a.c.must_equal 'CC'
241
- end
242
-
243
- end
244
-
245
- end
246
-
247
- context '#inspect' do
248
-
249
- it 'returns a printable inspect' do
250
- store.a.b = 'B'
251
- store.c.d = 'C'
252
- store.inspect.must_equal %{configatron.a.b = "B"\nconfigatron.c.d = "C"}
253
- end
254
- end
255
-
256
- end
@@ -1,5 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe Configatron do
4
-
5
- end
data/test/test_helper.rb DELETED
@@ -1,15 +0,0 @@
1
- require 'bundler/setup'
2
-
3
- require 'configatron' # and any other gems you need
4
-
5
- require 'minitest/autorun'
6
- require "mocha/setup"
7
- require 'mocha/mini_test'
8
-
9
- class MiniTest::Spec
10
-
11
- class << self
12
- alias :context :describe
13
- end
14
-
15
- end