const_conf 0.0.0 → 0.1.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.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/const_conf.gemspec +4 -4
- data/lib/const_conf/json_plugin.rb +25 -0
- data/lib/const_conf/setting.rb +1 -0
- data/lib/const_conf/tree.rb +1 -1
- data/lib/const_conf/version.rb +1 -1
- data/lib/const_conf/yaml_plugin.rb +29 -2
- data/lib/const_conf.rb +41 -8
- data/spec/const_conf_spec.rb +67 -11
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46f0215dedac0b12181bb9621013af573bd2b03e81a89840c09fab2759c88c7b
|
4
|
+
data.tar.gz: 5a4ee56d3186be9916bc137fe0826087a07c23bba9170e8cc2eb13aeaf0b1ccc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca385b1ae66ce0f2187f3dd6f54d572fd5138cc06cc10a292354bc3ca5a4b13abedd723d202b4dd98fcbc1334b8763cfe102936d7c98da8400b0e94a692442f2
|
7
|
+
data.tar.gz: 7901878fdbe3a08b9726f4d195e422ca93a4683cf37b1cc09edb1ffd7d6c57bdccefaa9706b212d2881ac09185e6c03f3ef7c811330793860fa1638eeb400db6
|
data/Rakefile
CHANGED
@@ -16,15 +16,15 @@ GemHadar do
|
|
16
16
|
EOT
|
17
17
|
test_dir 'spec'
|
18
18
|
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.AppleDouble', '.bundle',
|
19
|
-
'.yardoc', 'doc', 'tags', 'coverage'
|
19
|
+
'.yardoc', 'doc', 'tags', 'coverage', 'cscope.out', '.starscope.db'
|
20
20
|
package_ignore '.all_images.yml', '.gitignore', 'VERSION', '.utilsrc',
|
21
21
|
'.github', *Dir['.contexts/*']
|
22
22
|
readme 'README.md'
|
23
23
|
|
24
24
|
dependency 'tins', '~> 1.42'
|
25
|
-
dependency 'rails', '~> 8'
|
26
25
|
dependency 'json', '~> 2.0'
|
27
26
|
dependency 'complex_config', '~> 0.22'
|
27
|
+
dependency 'activesupport', '~> 8'
|
28
28
|
development_dependency 'debug'
|
29
29
|
development_dependency 'rspec', '~> 3.13'
|
30
30
|
development_dependency 'context_spook', '~> 0.3'
|
data/const_conf.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: const_conf 0.
|
2
|
+
# stub: const_conf 0.1.1 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "const_conf".freeze
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.1.1".freeze
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
@@ -22,14 +22,14 @@ Gem::Specification.new do |s|
|
|
22
22
|
|
23
23
|
s.specification_version = 4
|
24
24
|
|
25
|
-
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.
|
25
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.2".freeze])
|
26
26
|
s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
|
27
27
|
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.13".freeze])
|
28
28
|
s.add_development_dependency(%q<context_spook>.freeze, ["~> 0.3".freeze])
|
29
29
|
s.add_development_dependency(%q<all_images>.freeze, ["~> 0.6".freeze])
|
30
30
|
s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.22".freeze])
|
31
31
|
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.42".freeze])
|
32
|
-
s.add_runtime_dependency(%q<rails>.freeze, ["~> 8".freeze])
|
33
32
|
s.add_runtime_dependency(%q<json>.freeze, ["~> 2.0".freeze])
|
34
33
|
s.add_runtime_dependency(%q<complex_config>.freeze, ["~> 0.22".freeze])
|
34
|
+
s.add_runtime_dependency(%q<activesupport>.freeze, ["~> 8".freeze])
|
35
35
|
end
|
@@ -1,6 +1,31 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
|
+
# A module that provides functionality for reading and parsing JSON file
|
4
|
+
# contents as configuration values.
|
5
|
+
#
|
6
|
+
# The JSONPlugin module extends the ConstConf::Setting class to enable
|
7
|
+
# configuration settings that are sourced from JSON files. This allows for
|
8
|
+
# structured configuration data to be loaded from files and used within the
|
9
|
+
# application's configuration system, supporting both standard JSON parsing and
|
10
|
+
# environment-specific configuration loading.
|
3
11
|
module ConstConf::JSONPlugin
|
12
|
+
# Reads and parses a JSON file, optionally with environment-specific loading
|
13
|
+
#
|
14
|
+
# This method attempts to read and parse a JSON file at the specified path.
|
15
|
+
# It supports environment-specific configuration loading when the env
|
16
|
+
# parameter is provided. The method uses thread synchronization to ensure
|
17
|
+
# safe access to the ComplexConfig provider.
|
18
|
+
#
|
19
|
+
# @param path [String] the filesystem path to the JSON file to be read
|
20
|
+
# @param required [Boolean] whether the file is required to exist, defaults to false
|
21
|
+
#
|
22
|
+
# @return [Object, nil] the parsed JSON content as a Ruby object, or nil if
|
23
|
+
# the file doesn't exist and required is false
|
24
|
+
#
|
25
|
+
# @raise [ConstConf::RequiredValueNotConfigured] if the file does not exist
|
26
|
+
# and required is true
|
27
|
+
# @raise [ConstConf::RequiredValueNotConfigured] if env is true and RAILS_ENV
|
28
|
+
# is not set and no explicit environment is provided
|
4
29
|
def json(path, required: false, object_class: JSON::GenericObject)
|
5
30
|
if File.exist?(path)
|
6
31
|
JSON.load_file(path, object_class:)
|
data/lib/const_conf/setting.rb
CHANGED
data/lib/const_conf/tree.rb
CHANGED
data/lib/const_conf/version.rb
CHANGED
@@ -1,15 +1,42 @@
|
|
1
1
|
require 'complex_config'
|
2
2
|
|
3
|
+
# A module that provides functionality for reading and parsing YAML file
|
4
|
+
# contents as configuration values.
|
5
|
+
#
|
6
|
+
# The YAMLPlugin module extends the ConstConf::Setting class to enable
|
7
|
+
# configuration settings that are sourced from YAML files. This allows for
|
8
|
+
# structured configuration data to be loaded from files and used within the
|
9
|
+
# application's configuration system, supporting both standard YAML parsing and
|
10
|
+
# environment-specific configuration loading.
|
3
11
|
module ConstConf::YAMLPlugin
|
4
12
|
include ComplexConfig::Provider::Shortcuts
|
5
13
|
|
14
|
+
# Reads and parses a YAML file, optionally with environment-specific loading
|
15
|
+
#
|
16
|
+
# This method attempts to read and parse a YAML file at the specified path.
|
17
|
+
# It supports environment-specific configuration loading when the env
|
18
|
+
# parameter is provided. The method uses thread synchronization to ensure
|
19
|
+
# safe access to the ComplexConfig provider.
|
20
|
+
#
|
21
|
+
# @param path [String] the filesystem path to the YAML file to be read
|
22
|
+
# @param required [Boolean] whether the file is required to exist, defaults to false
|
23
|
+
# @param env [Boolean, String] whether to load environment-specific configuration,
|
24
|
+
# can be true to use RAILS_ENV or a specific environment string
|
25
|
+
#
|
26
|
+
# @return [Object, nil] the parsed YAML content as a Ruby object, or nil if
|
27
|
+
# the file doesn't exist and required is false
|
28
|
+
#
|
29
|
+
# @raise [ConstConf::RequiredValueNotConfigured] if the file does not exist
|
30
|
+
# and required is true
|
31
|
+
# @raise [ConstConf::RequiredValueNotConfigured] if env is true and RAILS_ENV
|
32
|
+
# is not set and no explicit environment is provided
|
6
33
|
def yaml(path, required: false, env: false)
|
7
34
|
if File.exist?(path)
|
8
35
|
ConstConf.monitor.synchronize do
|
9
36
|
config_dir = File.dirname(path)
|
10
37
|
ComplexConfig::Provider.config_dir = config_dir
|
11
|
-
ext
|
12
|
-
name
|
38
|
+
ext = File.extname(path)
|
39
|
+
name = File.basename(path, ext)
|
13
40
|
if env
|
14
41
|
env == true and env = ENV['RAILS_ENV']
|
15
42
|
if env
|
data/lib/const_conf.rb
CHANGED
@@ -20,7 +20,7 @@ require 'const_conf/json_plugin'
|
|
20
20
|
require 'const_conf/yaml_plugin'
|
21
21
|
require 'const_conf/env_dir_extension'
|
22
22
|
require 'const_conf/tree'
|
23
|
-
require 'const_conf/railtie'
|
23
|
+
require 'const_conf/railtie' if defined? Rails::Railtie
|
24
24
|
|
25
25
|
module ConstConf
|
26
26
|
include ConstConf::Errors
|
@@ -129,7 +129,9 @@ module ConstConf
|
|
129
129
|
#
|
130
130
|
# @param id [ Symbol ] the name of the constant being added
|
131
131
|
def const_added(id)
|
132
|
+
id = id.to_sym
|
132
133
|
if const = const_get(id) and const.is_a?(Module)
|
134
|
+
nested_module_constants << id
|
133
135
|
const.class_eval do
|
134
136
|
include ConstConf
|
135
137
|
end
|
@@ -165,6 +167,20 @@ module ConstConf
|
|
165
167
|
super if defined? super
|
166
168
|
end
|
167
169
|
|
170
|
+
# Removes a constant from the module and updates the nested module
|
171
|
+
# constants set.
|
172
|
+
#
|
173
|
+
# This method removes a constant from its parent module using the standard
|
174
|
+
# super mechanism and then removes the constant name from the
|
175
|
+
# nested_module_constants set to maintain consistency in tracking nested
|
176
|
+
# configuration modules.
|
177
|
+
#
|
178
|
+
# @param id [ Symbol ] the name of the constant to remove
|
179
|
+
private def remove_const(id)
|
180
|
+
super
|
181
|
+
nested_module_constants.delete(id.to_sym)
|
182
|
+
end
|
183
|
+
|
168
184
|
# Sets or retrieves the description for a ConstConf module.
|
169
185
|
#
|
170
186
|
# This method provides access to the description attribute of a
|
@@ -197,6 +213,22 @@ module ConstConf
|
|
197
213
|
@settings ||= {}
|
198
214
|
end
|
199
215
|
|
216
|
+
# Returns the set of nested module constants for the configuration in
|
217
|
+
# definition order.
|
218
|
+
#
|
219
|
+
# This method provides access to the internal storage that tracks which
|
220
|
+
# constants within a configuration module are themselves modules that
|
221
|
+
# include ConstConf. It ensures the set is initialized before returning it,
|
222
|
+
# guaranteeing that subsequent accesses will return the same set instance.
|
223
|
+
#
|
224
|
+
# @return [Set<Symbol>] the set containing the names of nested module constants
|
225
|
+
# @see #const_added
|
226
|
+
# @see #nested_configurations
|
227
|
+
# @see #all_configurations
|
228
|
+
def nested_module_constants
|
229
|
+
@nested_module_constants ||= Set[]
|
230
|
+
end
|
231
|
+
|
200
232
|
# The prefix reader accessor returns the configured prefix for the setting.
|
201
233
|
#
|
202
234
|
# @return [String, nil] the prefix value, or nil if not set
|
@@ -264,7 +296,7 @@ module ConstConf
|
|
264
296
|
# @return [ Array<Module> ] an array containing nested configuration
|
265
297
|
# modules that inherit from ConstConf
|
266
298
|
def nested_configurations
|
267
|
-
|
299
|
+
nested_module_constants.map { |c|
|
268
300
|
begin
|
269
301
|
m = const_get(c)
|
270
302
|
rescue NameError
|
@@ -377,9 +409,10 @@ module ConstConf
|
|
377
409
|
# Iterates over a configuration module and its nested configurations in a
|
378
410
|
# depth-first manner.
|
379
411
|
#
|
380
|
-
# This method yields each configuration module, including the receiver and
|
381
|
-
# in a depth-first traversal order. It is used
|
382
|
-
# settings across a module
|
412
|
+
# This method yields each configuration module, including the receiver and
|
413
|
+
# all nested modules, in a depth-first traversal order. It is used
|
414
|
+
# internally to process all configuration settings across a module
|
415
|
+
# hierarchy.
|
383
416
|
#
|
384
417
|
# @yield [ configuration ] yields each configuration module in the hierarchy
|
385
418
|
# @yieldparam configuration [ Module ] a configuration module from the hierarchy
|
@@ -389,12 +422,12 @@ module ConstConf
|
|
389
422
|
def each_nested_configuration(&block)
|
390
423
|
return enum_for(:each_nested_configuration) unless block_given?
|
391
424
|
configuration_modules = [ self ]
|
392
|
-
while configuration = configuration_modules.
|
393
|
-
|
394
|
-
configuration.nested_configurations.each do
|
425
|
+
while configuration = configuration_modules.pop
|
426
|
+
configuration.nested_configurations.reverse_each do
|
395
427
|
configuration_modules.member?(it) and next
|
396
428
|
configuration_modules << it
|
397
429
|
end
|
430
|
+
yield configuration
|
398
431
|
end
|
399
432
|
end
|
400
433
|
end
|
data/spec/const_conf_spec.rb
CHANGED
@@ -88,34 +88,60 @@ describe ConstConf do
|
|
88
88
|
module TestNestedConstConf
|
89
89
|
include ConstConf
|
90
90
|
|
91
|
-
|
91
|
+
module Zebra
|
92
|
+
description 'Last module defined'
|
92
93
|
|
93
|
-
|
94
|
-
|
94
|
+
module InnerZebra
|
95
|
+
description 'Inner zebra'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
module Alpha
|
100
|
+
description 'First module defined'
|
101
|
+
|
102
|
+
module InnerAlpha
|
103
|
+
description 'Inner alpha'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
module Beta
|
108
|
+
description 'Middle module defined'
|
109
|
+
|
110
|
+
module InnerBeta
|
111
|
+
description 'Inner beta'
|
112
|
+
end
|
95
113
|
end
|
96
114
|
end
|
97
115
|
end
|
98
116
|
|
99
117
|
describe '.outer_configuration' do
|
100
118
|
it 'knows about outer_configuration' do
|
101
|
-
expect(TestNestedConstConf::
|
119
|
+
expect(TestNestedConstConf::Zebra::InnerZebra.outer_configuration).
|
102
120
|
to eq TestNestedConstConf
|
103
121
|
end
|
104
122
|
end
|
105
123
|
|
106
124
|
describe '.all_configurations' do
|
107
125
|
it 'can return all configurations' do
|
108
|
-
expect(TestNestedConstConf.all_configurations).to eq
|
109
|
-
|
110
|
-
|
126
|
+
expect(TestNestedConstConf.all_configurations).to eq [
|
127
|
+
TestNestedConstConf,
|
128
|
+
TestNestedConstConf::Zebra,
|
129
|
+
TestNestedConstConf::Zebra::InnerZebra,
|
130
|
+
TestNestedConstConf::Alpha,
|
131
|
+
TestNestedConstConf::Alpha::InnerAlpha,
|
132
|
+
TestNestedConstConf::Beta,
|
133
|
+
TestNestedConstConf::Beta::InnerBeta,
|
134
|
+
]
|
111
135
|
end
|
112
136
|
end
|
113
137
|
|
114
138
|
describe '.nested_configurations' do
|
115
139
|
it 'can return nested configurations' do
|
116
|
-
expect(TestNestedConstConf.nested_configurations).to eq
|
117
|
-
|
118
|
-
|
140
|
+
expect(TestNestedConstConf.nested_configurations).to eq [
|
141
|
+
TestNestedConstConf::Zebra,
|
142
|
+
TestNestedConstConf::Alpha,
|
143
|
+
TestNestedConstConf::Beta,
|
144
|
+
]
|
119
145
|
end
|
120
146
|
|
121
147
|
describe '.each_nested_configuration' do
|
@@ -123,7 +149,37 @@ describe ConstConf do
|
|
123
149
|
expect(TestNestedConstConf.each_nested_configuration).
|
124
150
|
to be_a Enumerator
|
125
151
|
expect(TestNestedConstConf.each_nested_configuration.to_a).
|
126
|
-
to eq
|
152
|
+
to eq [
|
153
|
+
TestNestedConstConf,
|
154
|
+
TestNestedConstConf::Zebra,
|
155
|
+
TestNestedConstConf::Zebra::InnerZebra,
|
156
|
+
TestNestedConstConf::Alpha,
|
157
|
+
TestNestedConstConf::Alpha::InnerAlpha,
|
158
|
+
TestNestedConstConf::Beta,
|
159
|
+
TestNestedConstConf::Beta::InnerBeta,
|
160
|
+
]
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '.remove_const' do
|
165
|
+
it 'can remove a constant' do
|
166
|
+
expect(TestNestedConstConf.all_configurations).to eq [
|
167
|
+
TestNestedConstConf,
|
168
|
+
TestNestedConstConf::Zebra,
|
169
|
+
TestNestedConstConf::Zebra::InnerZebra,
|
170
|
+
TestNestedConstConf::Alpha,
|
171
|
+
TestNestedConstConf::Alpha::InnerAlpha,
|
172
|
+
TestNestedConstConf::Beta,
|
173
|
+
TestNestedConstConf::Beta::InnerBeta,
|
174
|
+
]
|
175
|
+
TestNestedConstConf.send(:remove_const, :Alpha)
|
176
|
+
expect(TestNestedConstConf.all_configurations).to eq [
|
177
|
+
TestNestedConstConf,
|
178
|
+
TestNestedConstConf::Zebra,
|
179
|
+
TestNestedConstConf::Zebra::InnerZebra,
|
180
|
+
TestNestedConstConf::Beta,
|
181
|
+
TestNestedConstConf::Beta::InnerBeta,
|
182
|
+
]
|
127
183
|
end
|
128
184
|
end
|
129
185
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: const_conf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
@@ -15,14 +15,14 @@ dependencies:
|
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: '2.
|
18
|
+
version: '2.2'
|
19
19
|
type: :development
|
20
20
|
prerelease: false
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
22
22
|
requirements:
|
23
23
|
- - "~>"
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version: '2.
|
25
|
+
version: '2.2'
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: debug
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,47 +108,47 @@ dependencies:
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '1.42'
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
111
|
+
name: json
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
116
|
+
version: '2.0'
|
117
117
|
type: :runtime
|
118
118
|
prerelease: false
|
119
119
|
version_requirements: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
123
|
+
version: '2.0'
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
|
-
name:
|
125
|
+
name: complex_config
|
126
126
|
requirement: !ruby/object:Gem::Requirement
|
127
127
|
requirements:
|
128
128
|
- - "~>"
|
129
129
|
- !ruby/object:Gem::Version
|
130
|
-
version: '
|
130
|
+
version: '0.22'
|
131
131
|
type: :runtime
|
132
132
|
prerelease: false
|
133
133
|
version_requirements: !ruby/object:Gem::Requirement
|
134
134
|
requirements:
|
135
135
|
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
137
|
+
version: '0.22'
|
138
138
|
- !ruby/object:Gem::Dependency
|
139
|
-
name:
|
139
|
+
name: activesupport
|
140
140
|
requirement: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
142
|
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
144
|
+
version: '8'
|
145
145
|
type: :runtime
|
146
146
|
prerelease: false
|
147
147
|
version_requirements: !ruby/object:Gem::Requirement
|
148
148
|
requirements:
|
149
149
|
- - "~>"
|
150
150
|
- !ruby/object:Gem::Version
|
151
|
-
version: '
|
151
|
+
version: '8'
|
152
152
|
description: |
|
153
153
|
ConstConf is a Ruby configuration library that manages settings
|
154
154
|
through environment variables, files, and directories with comprehensive
|