configatron 3.2.0 → 4.5.1

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +2 -2
  4. data/History.txt +72 -0
  5. data/README.md +25 -24
  6. data/Rakefile +10 -4
  7. data/configatron.gemspec +1 -0
  8. data/lib/configatron.rb +22 -4
  9. data/lib/configatron/core.rb +6 -6
  10. data/lib/configatron/ext/kernel.rb +5 -0
  11. data/lib/configatron/integrations.rb +4 -0
  12. data/lib/configatron/integrations/minitest.rb +29 -0
  13. data/lib/configatron/{rails.rb → integrations/rails.rb} +1 -1
  14. data/lib/configatron/root_store.rb +121 -0
  15. data/lib/configatron/store.rb +104 -67
  16. data/lib/configatron/version.rb +1 -1
  17. data/lib/generators/configatron/install/templates/configatron/defaults.rb +2 -2
  18. data/lib/generators/configatron/install/templates/configatron/development.rb +2 -2
  19. data/lib/generators/configatron/install/templates/configatron/production.rb +2 -2
  20. data/lib/generators/configatron/install/templates/configatron/test.rb +2 -2
  21. data/lib/generators/configatron/install/templates/initializers/configatron.rb +1 -1
  22. data/test/_lib.rb +17 -0
  23. data/test/functional/_lib.rb +10 -0
  24. data/test/functional/_lib/scripts/core.rb +11 -0
  25. data/test/functional/configatron.rb +165 -0
  26. data/test/functional/delayed.rb +18 -0
  27. data/test/functional/loading.rb +10 -0
  28. data/test/functional/minitest.rb +18 -0
  29. data/test/unit/_lib.rb +10 -0
  30. data/test/unit/configatron/proc.rb +24 -0
  31. data/test/unit/configatron/root_store.rb +37 -0
  32. data/test/unit/configatron/store.rb +149 -0
  33. metadata +55 -28
  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,69 @@
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.1
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-05-11 00:00:00.000000000 Z
11
+ date: 2017-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mocha
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: subprocess
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: minitest
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ">="
59
+ - - '>='
46
60
  - !ruby/object:Gem::Version
47
61
  version: 5.2.3
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - '>='
53
67
  - !ruby/object:Gem::Version
54
68
  version: 5.2.3
55
69
  description: A powerful Ruby configuration system.
@@ -59,12 +73,11 @@ executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
- - ".gitignore"
63
- - ".ruby-version"
64
- - ".travis.yml"
76
+ - .gitignore
77
+ - .travis.yml
65
78
  - Gemfile
66
- - Gemfile.lock
67
79
  - Guardfile
80
+ - History.txt
68
81
  - LICENSE.txt
69
82
  - README.md
70
83
  - Rakefile
@@ -72,13 +85,15 @@ files:
72
85
  - configatron.gemspec
73
86
  - lib/configatron.rb
74
87
  - lib/configatron/core.rb
75
- - lib/configatron/deep_clone.rb
76
88
  - lib/configatron/delayed.rb
77
89
  - lib/configatron/dynamic.rb
78
90
  - lib/configatron/errors.rb
79
- - lib/configatron/kernel.rb
91
+ - lib/configatron/ext/kernel.rb
92
+ - lib/configatron/integrations.rb
93
+ - lib/configatron/integrations/minitest.rb
94
+ - lib/configatron/integrations/rails.rb
80
95
  - lib/configatron/proc.rb
81
- - lib/configatron/rails.rb
96
+ - lib/configatron/root_store.rb
82
97
  - lib/configatron/store.rb
83
98
  - lib/configatron/version.rb
84
99
  - lib/generators/configatron/install/install_generator.rb
@@ -87,11 +102,17 @@ files:
87
102
  - lib/generators/configatron/install/templates/configatron/production.rb
88
103
  - lib/generators/configatron/install/templates/configatron/test.rb
89
104
  - 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
105
+ - test/_lib.rb
106
+ - test/functional/_lib.rb
107
+ - test/functional/_lib/scripts/core.rb
108
+ - test/functional/configatron.rb
109
+ - test/functional/delayed.rb
110
+ - test/functional/loading.rb
111
+ - test/functional/minitest.rb
112
+ - test/unit/_lib.rb
113
+ - test/unit/configatron/proc.rb
114
+ - test/unit/configatron/root_store.rb
115
+ - test/unit/configatron/store.rb
95
116
  homepage: https://github.com/markbates/configatron
96
117
  licenses:
97
118
  - MIT
@@ -102,23 +123,29 @@ require_paths:
102
123
  - lib
103
124
  required_ruby_version: !ruby/object:Gem::Requirement
104
125
  requirements:
105
- - - ">="
126
+ - - '>='
106
127
  - !ruby/object:Gem::Version
107
128
  version: '0'
108
129
  required_rubygems_version: !ruby/object:Gem::Requirement
109
130
  requirements:
110
- - - ">="
131
+ - - '>='
111
132
  - !ruby/object:Gem::Version
112
133
  version: '0'
113
134
  requirements: []
114
135
  rubyforge_project:
115
- rubygems_version: 2.2.1
136
+ rubygems_version: 2.0.14.1
116
137
  signing_key:
117
138
  specification_version: 4
118
139
  summary: A powerful Ruby configuration system.
119
140
  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
141
+ - test/_lib.rb
142
+ - test/functional/_lib.rb
143
+ - test/functional/_lib/scripts/core.rb
144
+ - test/functional/configatron.rb
145
+ - test/functional/delayed.rb
146
+ - test/functional/loading.rb
147
+ - test/functional/minitest.rb
148
+ - test/unit/_lib.rb
149
+ - test/unit/configatron/proc.rb
150
+ - test/unit/configatron/root_store.rb
151
+ - test/unit/configatron/store.rb