configatron 3.0.2 → 3.1.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/configatron.gemspec +2 -0
- data/lib/configatron/core.rb +4 -1
- data/lib/configatron/delayed.rb +2 -0
- data/lib/configatron/dynamic.rb +7 -0
- data/lib/configatron/proc.rb +30 -0
- data/lib/configatron/store.rb +5 -1
- data/lib/configatron/version.rb +1 -1
- data/test/configatron/proc_test.rb +27 -0
- data/test/configatron/store_test.rb +10 -0
- data/test/test_helper.rb +2 -0
- metadata +35 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84ff6f84518b18e89af32df3249a42d4adde63c6
|
4
|
+
data.tar.gz: ed208d199f8334bda0b371098eeaf9f035f390a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68368a752c61057a128b2a84f610e1d384a2ac198ab104689ec7129fb1723a4183dc864550914a08394fee2bf0301b2a3a33c3cd18ba11cc0ae30fd9ff95df5e
|
7
|
+
data.tar.gz: 178b8532496c4c85ef94a478073283d333ca37be95ecaa9c811bd996c54a9e0181a0cdbb73cd6970e3d4d6b9500d35f2bcdd4529fc46b82b78da45e9bc6fe9d5
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -49,7 +49,7 @@ configatron.database.url # => "postgres://localhost/foo"
|
|
49
49
|
|
50
50
|
Voila! Simple as can be.
|
51
51
|
|
52
|
-
Now you're saying, what if I want to have a 'default' set of options, but then override them later, based on other information? Simple again. Let's use our above example. We've configured our `database.url` option to be
|
52
|
+
Now you're saying, what if I want to have a 'default' set of options, but then override them later, based on other information? Simple again. Let's use our above example. We've configured our `database.url` option to be `postgres://localhost/foo`. The problem with that is that is our production database url, not our development url. Fair enough, all you have to do is redeclare it:
|
53
53
|
|
54
54
|
```ruby
|
55
55
|
configatron.database.url = "postgres://localhost/foo_development"
|
data/configatron.gemspec
CHANGED
data/lib/configatron/core.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
class Configatron
|
2
|
+
|
3
|
+
class Proc
|
4
|
+
|
5
|
+
attr_accessor :execution_count
|
6
|
+
attr_accessor :block
|
7
|
+
|
8
|
+
def initialize(&block)
|
9
|
+
self.execution_count = 0
|
10
|
+
self.block = block
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
unless @val
|
15
|
+
val = self.block.call
|
16
|
+
self.execution_count += 1
|
17
|
+
if finalize?
|
18
|
+
@val = val
|
19
|
+
end
|
20
|
+
end
|
21
|
+
return val || @val
|
22
|
+
end
|
23
|
+
|
24
|
+
def finalize?
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/configatron/store.rb
CHANGED
@@ -15,12 +15,13 @@ class Configatron
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def [](key)
|
18
|
-
fetch(key.to_sym) do
|
18
|
+
val = fetch(key.to_sym) do
|
19
19
|
if @__locked
|
20
20
|
raise Configatron::UndefinedKeyError.new("Key Not Found: #{key}")
|
21
21
|
end
|
22
22
|
::Configatron::Store.new
|
23
23
|
end
|
24
|
+
return val
|
24
25
|
end
|
25
26
|
|
26
27
|
def store(key, value)
|
@@ -40,6 +41,9 @@ class Configatron
|
|
40
41
|
end
|
41
42
|
store(key, val)
|
42
43
|
end
|
44
|
+
if val.is_a?(Configatron::Proc)
|
45
|
+
val = val.call
|
46
|
+
end
|
43
47
|
return val
|
44
48
|
end
|
45
49
|
|
data/lib/configatron/version.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
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
|
@@ -18,6 +18,16 @@ describe Configatron::Store do
|
|
18
18
|
store["unknown"].must_be_kind_of Configatron::Store
|
19
19
|
end
|
20
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
|
+
|
21
31
|
end
|
22
32
|
|
23
33
|
context "[]=" do
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configatron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Bates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mocha
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.2.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.2.3
|
27
55
|
description: A powerful Ruby configuration system.
|
28
56
|
email:
|
29
57
|
- mark@markbates.com
|
@@ -45,8 +73,11 @@ files:
|
|
45
73
|
- lib/configatron.rb
|
46
74
|
- lib/configatron/core.rb
|
47
75
|
- lib/configatron/deep_clone.rb
|
76
|
+
- lib/configatron/delayed.rb
|
77
|
+
- lib/configatron/dynamic.rb
|
48
78
|
- lib/configatron/errors.rb
|
49
79
|
- lib/configatron/kernel.rb
|
80
|
+
- lib/configatron/proc.rb
|
50
81
|
- lib/configatron/rails.rb
|
51
82
|
- lib/configatron/store.rb
|
52
83
|
- lib/configatron/version.rb
|
@@ -57,6 +88,7 @@ files:
|
|
57
88
|
- lib/generators/configatron/install/templates/configatron/test.rb
|
58
89
|
- lib/generators/configatron/install/templates/initializers/configatron.rb
|
59
90
|
- test/configatron/kernel_test.rb
|
91
|
+
- test/configatron/proc_test.rb
|
60
92
|
- test/configatron/store_test.rb
|
61
93
|
- test/configatron_test.rb
|
62
94
|
- test/test_helper.rb
|
@@ -86,6 +118,7 @@ specification_version: 4
|
|
86
118
|
summary: A powerful Ruby configuration system.
|
87
119
|
test_files:
|
88
120
|
- test/configatron/kernel_test.rb
|
121
|
+
- test/configatron/proc_test.rb
|
89
122
|
- test/configatron/store_test.rb
|
90
123
|
- test/configatron_test.rb
|
91
124
|
- test/test_helper.rb
|