configatron 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +5 -1
- data/README.md +5 -19
- data/lib/configatron/root_store.rb +4 -0
- data/lib/configatron/store.rb +5 -5
- data/lib/configatron/version.rb +1 -1
- data/test/functional/configatron.rb +7 -0
- data/test/unit/configatron/root_store.rb +21 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6c93e7ecc847458d9417c053fa4a93fba83b616
|
4
|
+
data.tar.gz: f8f87d9a27a7a0e9af621dc109dbf17a1b664054
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75cca363649f725091cfbe1b4e5d846d9a5a23b479a83163fd5e647be097353ae6cbbeae78a3bef5277d101cc837e9a88ab569d83f7c132f61ac1bf6b2fc20e8
|
7
|
+
data.tar.gz: 3e7f64f6a99e29280a6981b4188dd887f33998d6c785cf3e458f6ea039d3aac3fcc44cd9a2482111f1ed445e6d40c530881fe428f95ccf2b3ef06f3526f06784
|
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -66,7 +66,7 @@ Notice how our other configuration parameters haven't changed? Cool, eh?
|
|
66
66
|
|
67
67
|
### Hash/YAML
|
68
68
|
|
69
|
-
You can configure Configatron from a hash as well (this is
|
69
|
+
You can configure Configatron from a hash as well (this is particularly useful if you'd like to have configuration files):
|
70
70
|
|
71
71
|
```ruby
|
72
72
|
configatron.configure_from_hash(email: {pop: {address: 'pop.example.com', port: 110}}, smtp: {address: 'smtp.example.com'})
|
@@ -76,10 +76,6 @@ configatron.email.pop.port # => 110
|
|
76
76
|
# and so on...
|
77
77
|
```
|
78
78
|
|
79
|
-
#### YAML
|
80
|
-
|
81
|
-
YAML is terrible and should be driven from the face of the Earth. Because of this Configatron V3 does not support it. Sorry.
|
82
|
-
|
83
79
|
### Namespaces
|
84
80
|
|
85
81
|
The question that should be on your lips is what I need to have namespaced configuration parameters. It's easy! Configatron allows you to create namespaces.
|
@@ -119,7 +115,7 @@ end
|
|
119
115
|
|
120
116
|
### Temp Configurations
|
121
117
|
|
122
|
-
Sometimes in testing, or other situations, you want to temporarily change some settings. You can do this with the `temp` method:
|
118
|
+
Sometimes in testing, or other situations, you want to temporarily change some settings. You can do this with the `temp` method (only available on the top-level configatron `RootStore`):
|
123
119
|
|
124
120
|
```ruby
|
125
121
|
configatron.one = 1
|
@@ -191,15 +187,7 @@ Each time you call `configatron.current.time` it will return a new value to you.
|
|
191
187
|
|
192
188
|
### nil
|
193
189
|
|
194
|
-
Even if parameters haven't been set, you can still call them, but you'll get a `Configatron::Store` object back.
|
195
|
-
|
196
|
-
```ruby
|
197
|
-
configatron.i.dont.exist.nil? # => true
|
198
|
-
configatron.i.dont.exist.blank? # => true
|
199
|
-
configatron.i.dont.exist # => Configatron::Store
|
200
|
-
```
|
201
|
-
|
202
|
-
You can use `.has_key?` to determine if a key already exists.
|
190
|
+
Even if parameters haven't been set, you can still call them, but you'll get a `Configatron::Store` object back. You can use `.has_key?` to determine if a key already exists.
|
203
191
|
|
204
192
|
```ruby
|
205
193
|
configatron.i.dont.has_key?(:exist) # => false
|
@@ -218,16 +206,14 @@ configatron.a.b.c! # => raise Configratron::UndefinedKeyError
|
|
218
206
|
|
219
207
|
### Kernel
|
220
208
|
|
221
|
-
The `configatron` "helper" method is
|
222
|
-
|
223
|
-
Instead of requiring `configatron` simply require `configatron/core`, but then you'll have to set up your own `Configatron::Store` object.
|
209
|
+
The `configatron` "helper" method is stored in the `Kernel` module. You can opt-out of this global monkey-patching by requiring `configatron/core` rather than `configatron`. You'll have to set up your own `Configatron::RootStore` object.
|
224
210
|
|
225
211
|
Example:
|
226
212
|
|
227
213
|
```ruby
|
228
214
|
require 'configatron/core'
|
229
215
|
|
230
|
-
store = Configatron::
|
216
|
+
store = Configatron::RootStore.new
|
231
217
|
store.foo = 'FOO'
|
232
218
|
|
233
219
|
store.to_h #= {foo: 'FOO'}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# operate on the entire configatron hierarchy.
|
3
3
|
class Configatron::RootStore
|
4
4
|
include Singleton
|
5
|
+
extend ::Forwardable
|
5
6
|
|
6
7
|
attr_reader :store
|
7
8
|
|
@@ -49,4 +50,7 @@ class Configatron::RootStore
|
|
49
50
|
def unlock!
|
50
51
|
@locked = false
|
51
52
|
end
|
53
|
+
|
54
|
+
def_delegator :@store, :to_s
|
55
|
+
def_delegator :@store, :inspect
|
52
56
|
end
|
data/lib/configatron/store.rb
CHANGED
@@ -58,11 +58,6 @@ class Configatron
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
# Needed to allow 'puts'ing of a configatron.
|
62
|
-
def to_ary
|
63
|
-
raise NoMethodError
|
64
|
-
end
|
65
|
-
|
66
61
|
def to_s
|
67
62
|
@name
|
68
63
|
end
|
@@ -90,6 +85,11 @@ class Configatron
|
|
90
85
|
end
|
91
86
|
|
92
87
|
def method_missing(name, *args, &block)
|
88
|
+
# Needed to allow 'puts'ing of a configatron.
|
89
|
+
if name == :to_ary
|
90
|
+
raise NoMethodError.new("Called :to_ary")
|
91
|
+
end
|
92
|
+
|
93
93
|
# In case of Configatron bugs, prevent method_missing infinite
|
94
94
|
# loops.
|
95
95
|
if @method_missing
|
data/lib/configatron/version.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require_relative '../_lib'
|
2
2
|
|
3
|
-
class Critic::Unit::
|
3
|
+
class Critic::Unit::RootTest < Critic::Unit::Test
|
4
4
|
before do
|
5
|
-
@
|
5
|
+
@root = Configatron::RootStore.new
|
6
6
|
end
|
7
7
|
|
8
8
|
describe 'delegation' do
|
9
9
|
it 'passes on to Configatron::Store' do
|
10
|
-
@
|
11
|
-
assert_equal('D', @
|
10
|
+
@root.a.b.c.d = 'D'
|
11
|
+
assert_equal('D', @root.a.b.c.d)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -17,4 +17,21 @@ class Critic::Unit::KernelTest < Critic::Unit::Test
|
|
17
17
|
assert_equal(true, configatron.kind_of?(Configatron::RootStore))
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
describe 'inspect' do
|
22
|
+
it 'delegates to store' do
|
23
|
+
@root.a.b.c.d = 'D'
|
24
|
+
@root.a.b.e = 'E'
|
25
|
+
assert_equal('configatron.a.b.c.d = "D"
|
26
|
+
configatron.a.b.e = "E"', @root.inspect)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'to_s' do
|
31
|
+
it 'delegates to store' do
|
32
|
+
@root.a.b.c.d = 'D'
|
33
|
+
@root.a.b = 'D'
|
34
|
+
assert_equal('configatron', @root.to_s)
|
35
|
+
end
|
36
|
+
end
|
20
37
|
end
|