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
@@ -0,0 +1,18 @@
1
+ require_relative '_lib'
2
+
3
+ class Critic::Functional::DelayedTest < Critic::Functional::Test
4
+ before do
5
+ @kernel = Configatron::RootStore.new
6
+ end
7
+
8
+ describe 'delayed' do
9
+ before do
10
+ @kernel.a = Configatron::Delayed.new { @kernel.b }
11
+ @kernel.b = "expected"
12
+ end
13
+
14
+ it 'works independent of the order' do
15
+ assert_equal('expected', @kernel.a)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ require_relative '_lib'
2
+ require 'subprocess'
3
+
4
+ class Critic::Functional::ConfigatronTest < Critic::Functional::Test
5
+ describe 'loading' do
6
+ it 'does not define top-level configatron method if loading configatron/core' do
7
+ Subprocess.check_call([File.expand_path('../_lib/scripts/core.rb', __FILE__)])
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ require_relative '_lib'
2
+ require 'subprocess'
3
+
4
+ class Critic::Functional::MinitestTest < Critic::Functional::Test
5
+ include Configatron::Integrations::Minitest
6
+
7
+ describe 'multiple runs' do
8
+ it 'settings get reset: 1' do
9
+ assert(!configatron.key?(:my_crazy_setting))
10
+ configatron.my_crazy_setting = true
11
+ end
12
+
13
+ it 'settings get reset: 2' do
14
+ assert(!configatron.key?(:my_crazy_setting))
15
+ configatron.my_crazy_setting = true
16
+ end
17
+ end
18
+ end
data/test/unit/_lib.rb ADDED
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../../_lib', __FILE__)
2
+
3
+ module Critic::Unit
4
+ module Stubs
5
+ end
6
+
7
+ class Test < Critic::Test
8
+ include Stubs
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ require_relative '../_lib'
2
+
3
+ class Critic::Unit::ProcTest < Critic::Unit::Test
4
+ before do
5
+ @proc = Configatron::Proc.new {rand}
6
+ end
7
+
8
+ describe '#call' do
9
+ it 'executes the block and returns the results' do
10
+ stubs(:rand).returns(4)
11
+ assert_equal(4, @proc.call)
12
+ end
13
+
14
+ it 'caches the result if finalize? return true' do
15
+ @proc.stubs(:finalize?).returns(true)
16
+ assert_equal(@proc.call, @proc.call)
17
+ end
18
+
19
+ it 'does not cache the result if finalize? returns false' do
20
+ @proc.stubs(:finalize?).returns(false)
21
+ refute_equal(@proc.call, @proc.call)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ require_relative '../_lib'
2
+
3
+ class Critic::Unit::RootTest < Critic::Unit::Test
4
+ before do
5
+ @root = Configatron::RootStore.new
6
+ end
7
+
8
+ describe 'delegation' do
9
+ it 'passes on to Configatron::Store' do
10
+ @root.a.b.c.d = 'D'
11
+ assert_equal('D', @root.a.b.c.d)
12
+ end
13
+ end
14
+
15
+ describe 'global configatron' do
16
+ it 'returns an instance of Configatron::RootStore' do
17
+ assert_equal(Configatron::RootStore.instance, configatron)
18
+ end
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
37
+ end
@@ -0,0 +1,149 @@
1
+ require_relative '../_lib'
2
+
3
+ class Critic::Unit::StoreTest < Critic::Unit::Test
4
+ before do
5
+ @store = Configatron::Store.new(Configatron::RootStore.new)
6
+ @store.foo = 'bar'
7
+ end
8
+
9
+ describe "[]" do
10
+ it 'returns the value if there is one' do
11
+ assert_equal('bar', @store[:foo])
12
+ assert_equal('bar', @store['foo'])
13
+ end
14
+
15
+ it 'returns a new Configatron::Store object if there is no value' do
16
+ assert_kind_of(Configatron::Store, @store[:unknown])
17
+ assert_kind_of(Configatron::Store, @store['unknown'])
18
+ end
19
+
20
+ describe 'Configatron::Proc' do
21
+ it 'executes the proc' do
22
+ @store.a = Configatron::Proc.new {1+1}
23
+ assert_equal(2, @store.a)
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ describe '[]=' do
30
+ it "sets the value" do
31
+ @store[:foo] = "bar"
32
+ assert_equal("bar", @store[:foo])
33
+ assert_equal("bar", @store["foo"])
34
+
35
+ @store[:baz] = "bazzy"
36
+ assert_equal("bazzy", @store[:baz])
37
+ assert_equal("bazzy", @store["baz"])
38
+ end
39
+ end
40
+
41
+ describe "fetch" do
42
+ it "returns the value" do
43
+ assert_equal("bar", @store.fetch(:foo))
44
+ assert_equal("bar", @store.fetch("foo"))
45
+ end
46
+
47
+ it "sets and returns the value of the default_value if no value is found" do
48
+ assert_equal("bar!!", @store.fetch(:bar, "bar!!"))
49
+ assert_equal("bar!!", @store.bar)
50
+ end
51
+
52
+ it "sets and returns the value of the block if no value is found" do
53
+ @store.fetch(:bar) do
54
+ "bar!"
55
+ end
56
+ assert_equal("bar!", @store.bar)
57
+ end
58
+ end
59
+
60
+ describe "key?" do
61
+ it "returns true if there is a key" do
62
+ assert_equal(false, @store.key?(:bar))
63
+ @store.bar = "bar"
64
+ assert_equal(true, @store.key?(:bar))
65
+ end
66
+
67
+ it "returns true if the key is a Configatron::Store" do
68
+ assert_equal(false, @store.key?(:bar))
69
+ @store.bar = Configatron::Store.new(Configatron::RootStore.new)
70
+ assert_equal(true, @store.key?(:bar))
71
+ end
72
+ end
73
+
74
+ describe "has_key?" do
75
+ it "returns true if there is a key" do
76
+ assert_equal(false, @store.has_key?(:bar))
77
+ @store.bar = "bar"
78
+ assert_equal(true, @store.has_key?(:bar))
79
+ end
80
+
81
+ it "returns true if the key is a Configatron::Store" do
82
+ assert_equal(false, @store.has_key?(:bar))
83
+ @store.bar = Configatron::Store.new(Configatron::RootStore.new)
84
+ assert_equal(true, @store.has_key?(:bar))
85
+ end
86
+ end
87
+
88
+ describe "method_missing" do
89
+ it "returns the value if there is one" do
90
+ assert_equal("bar", @store.foo)
91
+ end
92
+
93
+ it "returns a Configatron::Store if there is no value" do
94
+ assert_kind_of(Configatron::Store, @store.bar)
95
+ end
96
+
97
+ it "works with deeply nested values" do
98
+ @store.a.b.c.d = "DD"
99
+ assert_equal("DD", @store.a.b.c.d)
100
+ end
101
+
102
+ describe 'with bang' do
103
+ it "raises an exception if the key doesn't exist" do
104
+ assert_raises(Configatron::UndefinedKeyError) do
105
+ @store.a.b!
106
+ end
107
+ end
108
+
109
+ it "returns the value" do
110
+ @store.a.b = 'B'
111
+ assert_equal('B', @store.a.b!)
112
+ end
113
+ end
114
+ end
115
+
116
+ describe "configuring" do
117
+ describe "configure_from_hash" do
118
+ it "allows setup from a hash" do
119
+ @store.configure_from_hash(one: 1, a: {b: {c: {d: "DD"}}})
120
+ assert_equal(1, @store.one)
121
+ assert_equal("DD", @store.a.b.c.d)
122
+ end
123
+ end
124
+
125
+ describe "with a block" do
126
+ before do
127
+ @store.a.b = 'B'
128
+ end
129
+
130
+ it "yields up the store to configure with" do
131
+ @store.a do |a|
132
+ a.c = 'CC'
133
+ end
134
+ assert_equal('B', @store.a.b)
135
+ assert_equal('CC', @store.a.c)
136
+ end
137
+ end
138
+ end
139
+
140
+ describe '#inspect' do
141
+ it 'returns a printable inspect' do
142
+ store = Configatron::Store.new(Configatron::RootStore.new)
143
+
144
+ store.a.b = 'B'
145
+ store.c.d = 'C'
146
+ assert_equal(%{configatron.a.b = "B"\nconfigatron.c.d = "C"}, store.inspect)
147
+ end
148
+ end
149
+ end
metadata CHANGED
@@ -1,55 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configatron
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 4.5.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Mark Bates
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-05-11 00:00:00.000000000 Z
12
+ date: 2014-12-17 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rake
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - ">="
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - ">="
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: mocha
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - ">="
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: '0'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - ">="
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: subprocess
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
39
60
  - !ruby/object:Gem::Version
40
61
  version: '0'
41
62
  - !ruby/object:Gem::Dependency
42
63
  name: minitest
43
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
44
66
  requirements:
45
- - - ">="
67
+ - - ! '>='
46
68
  - !ruby/object:Gem::Version
47
69
  version: 5.2.3
48
70
  type: :development
49
71
  prerelease: false
50
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
51
74
  requirements:
52
- - - ">="
75
+ - - ! '>='
53
76
  - !ruby/object:Gem::Version
54
77
  version: 5.2.3
55
78
  description: A powerful Ruby configuration system.
@@ -59,12 +82,11 @@ executables: []
59
82
  extensions: []
60
83
  extra_rdoc_files: []
61
84
  files:
62
- - ".gitignore"
63
- - ".ruby-version"
64
- - ".travis.yml"
85
+ - .gitignore
86
+ - .travis.yml
65
87
  - Gemfile
66
- - Gemfile.lock
67
88
  - Guardfile
89
+ - History.txt
68
90
  - LICENSE.txt
69
91
  - README.md
70
92
  - Rakefile
@@ -72,13 +94,15 @@ files:
72
94
  - configatron.gemspec
73
95
  - lib/configatron.rb
74
96
  - lib/configatron/core.rb
75
- - lib/configatron/deep_clone.rb
76
97
  - lib/configatron/delayed.rb
77
98
  - lib/configatron/dynamic.rb
78
99
  - lib/configatron/errors.rb
79
- - lib/configatron/kernel.rb
100
+ - lib/configatron/ext/kernel.rb
101
+ - lib/configatron/integrations.rb
102
+ - lib/configatron/integrations/minitest.rb
103
+ - lib/configatron/integrations/rails.rb
80
104
  - lib/configatron/proc.rb
81
- - lib/configatron/rails.rb
105
+ - lib/configatron/root_store.rb
82
106
  - lib/configatron/store.rb
83
107
  - lib/configatron/version.rb
84
108
  - lib/generators/configatron/install/install_generator.rb
@@ -87,38 +111,57 @@ files:
87
111
  - lib/generators/configatron/install/templates/configatron/production.rb
88
112
  - lib/generators/configatron/install/templates/configatron/test.rb
89
113
  - lib/generators/configatron/install/templates/initializers/configatron.rb
90
- - test/configatron/kernel_test.rb
91
- - test/configatron/proc_test.rb
92
- - test/configatron/store_test.rb
93
- - test/configatron_test.rb
94
- - test/test_helper.rb
114
+ - test/_lib.rb
115
+ - test/functional/_lib.rb
116
+ - test/functional/_lib/scripts/core.rb
117
+ - test/functional/configatron.rb
118
+ - test/functional/delayed.rb
119
+ - test/functional/loading.rb
120
+ - test/functional/minitest.rb
121
+ - test/unit/_lib.rb
122
+ - test/unit/configatron/proc.rb
123
+ - test/unit/configatron/root_store.rb
124
+ - test/unit/configatron/store.rb
95
125
  homepage: https://github.com/markbates/configatron
96
126
  licenses:
97
127
  - MIT
98
- metadata: {}
99
128
  post_install_message:
100
129
  rdoc_options: []
101
130
  require_paths:
102
131
  - lib
103
132
  required_ruby_version: !ruby/object:Gem::Requirement
133
+ none: false
104
134
  requirements:
105
- - - ">="
135
+ - - ! '>='
106
136
  - !ruby/object:Gem::Version
107
137
  version: '0'
138
+ segments:
139
+ - 0
140
+ hash: -3612198204560107212
108
141
  required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
109
143
  requirements:
110
- - - ">="
144
+ - - ! '>='
111
145
  - !ruby/object:Gem::Version
112
146
  version: '0'
147
+ segments:
148
+ - 0
149
+ hash: -3612198204560107212
113
150
  requirements: []
114
151
  rubyforge_project:
115
- rubygems_version: 2.2.1
152
+ rubygems_version: 1.8.25
116
153
  signing_key:
117
- specification_version: 4
154
+ specification_version: 3
118
155
  summary: A powerful Ruby configuration system.
119
156
  test_files:
120
- - test/configatron/kernel_test.rb
121
- - test/configatron/proc_test.rb
122
- - test/configatron/store_test.rb
123
- - test/configatron_test.rb
124
- - test/test_helper.rb
157
+ - test/_lib.rb
158
+ - test/functional/_lib.rb
159
+ - test/functional/_lib/scripts/core.rb
160
+ - test/functional/configatron.rb
161
+ - test/functional/delayed.rb
162
+ - test/functional/loading.rb
163
+ - test/functional/minitest.rb
164
+ - test/unit/_lib.rb
165
+ - test/unit/configatron/proc.rb
166
+ - test/unit/configatron/root_store.rb
167
+ - test/unit/configatron/store.rb