configatronn 4.5.2

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 +7 -0
  2. data/.github/workflows/test.yml +27 -0
  3. data/.gitignore +22 -0
  4. data/Gemfile +6 -0
  5. data/History.txt +82 -0
  6. data/LICENSE.txt +23 -0
  7. data/README.md +312 -0
  8. data/Rakefile +15 -0
  9. data/configatronn.gemspec +28 -0
  10. data/lib/configatron/core.rb +6 -0
  11. data/lib/configatron/delayed.rb +2 -0
  12. data/lib/configatron/dynamic.rb +7 -0
  13. data/lib/configatron/errors.rb +9 -0
  14. data/lib/configatron/ext/kernel.rb +5 -0
  15. data/lib/configatron/integrations/minitest.rb +29 -0
  16. data/lib/configatron/integrations/rails.rb +53 -0
  17. data/lib/configatron/integrations.rb +4 -0
  18. data/lib/configatron/proc.rb +34 -0
  19. data/lib/configatron/root_store.rb +126 -0
  20. data/lib/configatron/store.rb +182 -0
  21. data/lib/configatron/version.rb +3 -0
  22. data/lib/configatron.rb +23 -0
  23. data/lib/generators/configatron/install/install_generator.rb +24 -0
  24. data/lib/generators/configatron/install/templates/configatron/defaults.rb +7 -0
  25. data/lib/generators/configatron/install/templates/configatron/development.rb +4 -0
  26. data/lib/generators/configatron/install/templates/configatron/production.rb +4 -0
  27. data/lib/generators/configatron/install/templates/configatron/test.rb +4 -0
  28. data/lib/generators/configatron/install/templates/initializers/configatron.rb +2 -0
  29. data/test/_lib.rb +17 -0
  30. data/test/functional/_lib/scripts/core.rb +11 -0
  31. data/test/functional/_lib.rb +10 -0
  32. data/test/functional/configatron.rb +194 -0
  33. data/test/functional/delayed.rb +18 -0
  34. data/test/functional/loading.rb +10 -0
  35. data/test/functional/minitest.rb +18 -0
  36. data/test/functional/rails.rb +94 -0
  37. data/test/unit/_lib.rb +10 -0
  38. data/test/unit/configatron/proc.rb +24 -0
  39. data/test/unit/configatron/root_store.rb +37 -0
  40. data/test/unit/configatron/store.rb +149 -0
  41. metadata +203 -0
@@ -0,0 +1,94 @@
1
+ # ruby
2
+
3
+ require 'minitest/autorun'
4
+ require 'tmpdir'
5
+ require 'fileutils'
6
+
7
+ module Critic
8
+ module Functional
9
+ class RailsTest < Critic::Functional::Test
10
+ def setup
11
+ @original_dir = Dir.pwd
12
+ @temp_dir = Dir.mktmpdir
13
+ Dir.chdir(@temp_dir)
14
+ create_default_config_file
15
+ create_rails_config_file
16
+ create_specific_config_files
17
+ end
18
+
19
+ def create_default_config_file
20
+ @default_root_dir = File.join(FileUtils.pwd)
21
+ default_dir = File.join(@default_root_dir, 'config', 'configatron')
22
+ FileUtils.mkdir_p(default_dir)
23
+ write_config(File.join(default_dir, 'defaults.rb'), 'configatron.default.defaults.a = 1')
24
+ write_config(File.join(default_dir, 'defaults.rb'), 'configatron.default.defaults.b = 2')
25
+ write_config(File.join(default_dir, 'development.rb'), 'configatron.default.development.c = 3')
26
+ write_config(File.join(default_dir, 'development.rb'), 'configatron.default.development.d = 4')
27
+ write_config(File.join(default_dir, 'test.rb'), 'configatron.default.test.e = 5')
28
+ write_config(File.join(default_dir, 'test.rb'), 'configatron.default.test.f = 6')
29
+ end
30
+
31
+ def create_rails_config_file
32
+ @rails_root_dir = File.join(FileUtils.pwd, 'rails_root')
33
+ rails_dir = File.join(@rails_root_dir, 'config', 'configatron')
34
+ FileUtils.mkdir_p(rails_dir)
35
+ write_config(File.join(rails_dir, 'defaults.rb'), 'configatron.rails.defaults.a = 7')
36
+ write_config(File.join(rails_dir, 'defaults.rb'), 'configatron.rails.defaults.b = 8')
37
+ write_config(File.join(rails_dir, 'development.rb'), 'configatron.rails.development.c = 9')
38
+ write_config(File.join(rails_dir, 'development.rb'), 'configatron.rails.development.d = 10')
39
+ write_config(File.join(rails_dir, 'test.rb'), 'configatron.rails.test.e = 11')
40
+ write_config(File.join(rails_dir, 'test.rb'), 'configatron.rails.test.f = 12')
41
+ end
42
+
43
+ def create_specific_config_files # rubocop:disable Metrics/AbcSize
44
+ @test_root_dir = File.join(FileUtils.pwd, 'test_root')
45
+ FileUtils.mkdir_p(@test_root_dir)
46
+ write_config(File.join(@test_root_dir, 'defaults.rb'), 'configatron.test_root.defaults.a = 13')
47
+ write_config(File.join(@test_root_dir, 'defaults.rb'), 'configatron.test_root.defaults.b = 14')
48
+ write_config(File.join(@test_root_dir, 'development.rb'), 'configatron.test_root.development.c = 15')
49
+ write_config(File.join(@test_root_dir, 'development.rb'), 'configatron.test_root.development.d = 16')
50
+ write_config(File.join(@test_root_dir, 'test.rb'), 'configatron.test_root.test.e = 17')
51
+ write_config(File.join(@test_root_dir, 'test.rb'), 'configatron.test_root.test.f = 18')
52
+ write_config(File.join(@test_root_dir, 'production.rb'), 'configatron.test_root.production.g = 19')
53
+ write_config(File.join(@test_root_dir, 'production.rb'), 'configatron.test_root.production.h = 20')
54
+ end
55
+
56
+ def write_config(path, context)
57
+ File.open(path, 'a') { |f| f.puts context }
58
+ end
59
+
60
+ def teardown
61
+ Dir.chdir(@original_dir)
62
+ FileUtils.remove_entry(@temp_dir) if Dir.exist?(@temp_dir)
63
+ Object.send(:remove_const, :Rails) if Object.const_defined?(:Rails)
64
+ configatron.reset!
65
+ end
66
+
67
+ it 'loads configuration files without Rails' do
68
+ Configatron::Integrations::Rails.init
69
+ assert_equal({ default: { defaults: { a: 1, b: 2 }, development: { c: 3, d: 4 } } }, configatron.to_h)
70
+ end
71
+
72
+ it 'loads configuration files with Rails' do
73
+ Object.const_set(:Rails, Module.new)
74
+ ::Rails.stubs(:root).returns(@rails_root_dir)
75
+ ::Rails.stubs(:env).returns('test')
76
+ Configatron::Integrations::Rails.init
77
+ assert_equal({ rails: { defaults: { a: 7, b: 8 }, test: { e: 11, f: 12 } } }, configatron.to_h)
78
+ end
79
+
80
+ it 'loads specific configuration files without Rails' do
81
+ Configatron::Integrations::Rails.init(@test_root_dir, 'production')
82
+ assert_equal({ test_root: { defaults: { a: 13, b: 14 }, production: { g: 19, h: 20 } } }, configatron.to_h)
83
+ end
84
+
85
+ it 'loads specific configuration files with Rails' do
86
+ Object.const_set(:Rails, Module.new)
87
+ ::Rails.stubs(:root).returns(@rails_root_dir)
88
+ ::Rails.stubs(:env).returns('test')
89
+ Configatron::Integrations::Rails.init(@test_root_dir, 'production')
90
+ assert_equal({ test_root: { defaults: { a: 13, b: 14 }, production: { g: 19, h: 20 } } }, configatron.to_h)
91
+ end
92
+ end
93
+ end
94
+ 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 ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: configatronn
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.5.2
5
+ platform: ruby
6
+ authors:
7
+ - Taku Shimizu
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: minitest
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 5.2.3
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 5.2.3
26
+ - !ruby/object:Gem::Dependency
27
+ name: mocha
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rake
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rubocop
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rubocop-minitest
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rubocop-performance
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: rubocop-rake
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: subprocess
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ description: A powerful Ruby configuration system.
125
+ email:
126
+ - t_shimizu@soloshmz.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - ".github/workflows/test.yml"
132
+ - ".gitignore"
133
+ - Gemfile
134
+ - History.txt
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - configatronn.gemspec
139
+ - lib/configatron.rb
140
+ - lib/configatron/core.rb
141
+ - lib/configatron/delayed.rb
142
+ - lib/configatron/dynamic.rb
143
+ - lib/configatron/errors.rb
144
+ - lib/configatron/ext/kernel.rb
145
+ - lib/configatron/integrations.rb
146
+ - lib/configatron/integrations/minitest.rb
147
+ - lib/configatron/integrations/rails.rb
148
+ - lib/configatron/proc.rb
149
+ - lib/configatron/root_store.rb
150
+ - lib/configatron/store.rb
151
+ - lib/configatron/version.rb
152
+ - lib/generators/configatron/install/install_generator.rb
153
+ - lib/generators/configatron/install/templates/configatron/defaults.rb
154
+ - lib/generators/configatron/install/templates/configatron/development.rb
155
+ - lib/generators/configatron/install/templates/configatron/production.rb
156
+ - lib/generators/configatron/install/templates/configatron/test.rb
157
+ - lib/generators/configatron/install/templates/initializers/configatron.rb
158
+ - test/_lib.rb
159
+ - test/functional/_lib.rb
160
+ - test/functional/_lib/scripts/core.rb
161
+ - test/functional/configatron.rb
162
+ - test/functional/delayed.rb
163
+ - test/functional/loading.rb
164
+ - test/functional/minitest.rb
165
+ - test/functional/rails.rb
166
+ - test/unit/_lib.rb
167
+ - test/unit/configatron/proc.rb
168
+ - test/unit/configatron/root_store.rb
169
+ - test/unit/configatron/store.rb
170
+ homepage: https://github.com/shi-tak/configatronn
171
+ licenses:
172
+ - MIT
173
+ metadata: {}
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubygems_version: 3.7.1
189
+ specification_version: 4
190
+ summary: A powerful Ruby configuration system.
191
+ test_files:
192
+ - test/_lib.rb
193
+ - test/functional/_lib.rb
194
+ - test/functional/_lib/scripts/core.rb
195
+ - test/functional/configatron.rb
196
+ - test/functional/delayed.rb
197
+ - test/functional/loading.rb
198
+ - test/functional/minitest.rb
199
+ - test/functional/rails.rb
200
+ - test/unit/_lib.rb
201
+ - test/unit/configatron/proc.rb
202
+ - test/unit/configatron/root_store.rb
203
+ - test/unit/configatron/store.rb