confg 3.0.1 → 3.3.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/confg.gemspec +10 -3
- data/lib/confg/configuration.rb +19 -0
- data/lib/confg/version.rb +5 -1
- metadata +11 -24
- data/.gitignore +0 -17
- data/.ruby-version +0 -1
- data/Gemfile +0 -4
- data/README.md +0 -54
- data/Rakefile +0 -12
- data/test/confg_test.rb +0 -95
- data/test/example.yml +0 -10
- data/test/example_with_symbols.yml +0 -10
- data/test/test_helper.rb +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1a8d68f7467992b67e6498153d220d203432287054549f768546f70127e6923f
|
|
4
|
+
data.tar.gz: add43866b97a32d137455b63a79778669310fda072ecb79d6f22937fef0b17c6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6203dc566bdfa5bc6c4acc16a8e610384f225d7aa221f26e6f40e71824922b78aa78d9335bbea1755e0bf88831f2b29eb6feca7f96c64a0290e82afe74f36261
|
|
7
|
+
data.tar.gz: f47490f355212bdb0d62cf24440405377f52f99f417d918ca795abdaa408264a87d96d74ee6c01eafade40532e93fd330568d2329b3b3be9fd57311a26aac6e7
|
data/confg.gemspec
CHANGED
|
@@ -11,15 +11,22 @@ Gem::Specification.new do |spec|
|
|
|
11
11
|
spec.email = ["mike@mnelson.io"]
|
|
12
12
|
spec.description = "Config the pipes"
|
|
13
13
|
spec.summary = "Sets shared variables for applications"
|
|
14
|
-
spec.homepage = ""
|
|
14
|
+
spec.homepage = "https://github.com/guideline-tech/confg"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
|
18
|
+
spec.files = Dir["lib/**/*"] + Dir["*.gemspec"]
|
|
15
19
|
|
|
16
|
-
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
|
17
20
|
spec.executables = spec.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
21
|
spec.require_paths = ["lib"]
|
|
20
22
|
|
|
23
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
24
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
25
|
+
|
|
21
26
|
spec.add_development_dependency "bundler"
|
|
22
27
|
spec.add_development_dependency "byebug"
|
|
23
28
|
spec.add_development_dependency "minitest", "~> 5.0"
|
|
24
29
|
spec.add_development_dependency "rake"
|
|
30
|
+
|
|
31
|
+
spec.required_ruby_version = ">= 3.2.0"
|
|
25
32
|
end
|
data/lib/confg/configuration.rb
CHANGED
|
@@ -32,6 +32,25 @@ module Confg
|
|
|
32
32
|
end
|
|
33
33
|
alias merge! merge
|
|
34
34
|
|
|
35
|
+
def load_env(prefix: "CONFG_", separator: "__")
|
|
36
|
+
overrides = {}
|
|
37
|
+
|
|
38
|
+
ENV.each do |key, value|
|
|
39
|
+
next unless key.start_with?(prefix)
|
|
40
|
+
|
|
41
|
+
segments = key.delete_prefix(prefix).downcase.split(separator)
|
|
42
|
+
|
|
43
|
+
# Build nested hash: ["database", "host"] => { "database" => { "host" => value } }
|
|
44
|
+
current = overrides
|
|
45
|
+
segments[0...-1].each do |segment|
|
|
46
|
+
current = (current[segment] ||= {})
|
|
47
|
+
end
|
|
48
|
+
current[segments.last] = value
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
merge(overrides)
|
|
52
|
+
end
|
|
53
|
+
|
|
35
54
|
def to_h
|
|
36
55
|
confg_data.transform_values do |v|
|
|
37
56
|
v.is_a?(self.class) ? v.to_h : v
|
data/lib/confg/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: confg
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0
|
|
4
|
+
version: 3.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Nelson
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: bundler
|
|
@@ -73,24 +72,17 @@ executables: []
|
|
|
73
72
|
extensions: []
|
|
74
73
|
extra_rdoc_files: []
|
|
75
74
|
files:
|
|
76
|
-
- ".gitignore"
|
|
77
|
-
- ".ruby-version"
|
|
78
|
-
- Gemfile
|
|
79
|
-
- README.md
|
|
80
|
-
- Rakefile
|
|
81
75
|
- confg.gemspec
|
|
82
76
|
- lib/confg.rb
|
|
83
77
|
- lib/confg/configuration.rb
|
|
84
78
|
- lib/confg/erb_context.rb
|
|
85
79
|
- lib/confg/version.rb
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
metadata: {}
|
|
93
|
-
post_install_message:
|
|
80
|
+
homepage: https://github.com/guideline-tech/confg
|
|
81
|
+
licenses:
|
|
82
|
+
- MIT
|
|
83
|
+
metadata:
|
|
84
|
+
allowed_push_host: https://rubygems.org
|
|
85
|
+
rubygems_mfa_required: 'true'
|
|
94
86
|
rdoc_options: []
|
|
95
87
|
require_paths:
|
|
96
88
|
- lib
|
|
@@ -98,19 +90,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
98
90
|
requirements:
|
|
99
91
|
- - ">="
|
|
100
92
|
- !ruby/object:Gem::Version
|
|
101
|
-
version:
|
|
93
|
+
version: 3.2.0
|
|
102
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
95
|
requirements:
|
|
104
96
|
- - ">="
|
|
105
97
|
- !ruby/object:Gem::Version
|
|
106
98
|
version: '0'
|
|
107
99
|
requirements: []
|
|
108
|
-
rubygems_version: 3.2
|
|
109
|
-
signing_key:
|
|
100
|
+
rubygems_version: 3.7.2
|
|
110
101
|
specification_version: 4
|
|
111
102
|
summary: Sets shared variables for applications
|
|
112
|
-
test_files:
|
|
113
|
-
- test/confg_test.rb
|
|
114
|
-
- test/example.yml
|
|
115
|
-
- test/example_with_symbols.yml
|
|
116
|
-
- test/test_helper.rb
|
|
103
|
+
test_files: []
|
data/.gitignore
DELETED
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
3.0.6
|
data/Gemfile
DELETED
data/README.md
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# Confg
|
|
2
|
-
|
|
3
|
-
Provides a utility for loading and managing configurations for your ruby project.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
Set specific keys:
|
|
8
|
-
|
|
9
|
-
Confg.configure do |c|
|
|
10
|
-
c.foo_setting = 100
|
|
11
|
-
c.bar_setting = "yes"
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
Supports nesting:
|
|
15
|
-
|
|
16
|
-
Confg.configure do |c|
|
|
17
|
-
c.api_keys do |a|
|
|
18
|
-
a.google = 'xyz'
|
|
19
|
-
a.mixpanel = 'abc'
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
Load a yaml file:
|
|
24
|
-
|
|
25
|
-
Confg.configure do |c|
|
|
26
|
-
c.load_yaml "/path/to/file.yml"
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
Yaml files can be namespaced by environment and contain ERB.
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
development:
|
|
33
|
-
thing: <%= ENV["THING"] %>
|
|
34
|
-
staging:
|
|
35
|
-
thing: 'set value'
|
|
36
|
-
|
|
37
|
-
Use the values:
|
|
38
|
-
|
|
39
|
-
Confg.foo_setting
|
|
40
|
-
#=> 100
|
|
41
|
-
|
|
42
|
-
Confg.api_keys
|
|
43
|
-
#=> #<Confg::Configuration { "google" => "xyz", "mixpanel" => "abc" }>
|
|
44
|
-
|
|
45
|
-
Confg.api_keys.google # => "xyz"'
|
|
46
|
-
|
|
47
|
-
Confg.api_keys.to_h
|
|
48
|
-
#=> { "google" => "xyz", "mixpanel" => "abc" }
|
|
49
|
-
|
|
50
|
-
Confg.missing_key
|
|
51
|
-
#=> raises KeyError
|
|
52
|
-
|
|
53
|
-
Conf[:missing_key]
|
|
54
|
-
#=> nil
|
data/Rakefile
DELETED
data/test/confg_test.rb
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "test_helper"
|
|
4
|
-
|
|
5
|
-
class ConfgTest < Minitest::Test
|
|
6
|
-
|
|
7
|
-
def config
|
|
8
|
-
@config ||= ::Confg::Configuration.new(root: __dir__, env: "test")
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def test_simple_keys_can_be_assigned
|
|
12
|
-
config.foo = "bar"
|
|
13
|
-
assert_equal "bar", config.foo
|
|
14
|
-
assert_equal({ "foo" => "bar" }, config.to_h)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def test_a_child_block_can_be_opened
|
|
18
|
-
config.open :foo do |child|
|
|
19
|
-
child.bar = "baz"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
assert_equal "baz", config.foo.bar
|
|
23
|
-
assert_equal({ "foo" => { "bar" => "baz" } }, config.to_h)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def test_a_child_block_can_be_merged_by_assigning_a_hash
|
|
27
|
-
config.foo = { "bar" => "baz" }
|
|
28
|
-
assert_equal "baz", config.foo.bar
|
|
29
|
-
assert_equal({ "foo" => { "bar" => "baz" } }, config.to_h)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def test_an_error_is_raised_for_a_missing_key
|
|
33
|
-
assert_raises KeyError do
|
|
34
|
-
config.foo
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_hash_methods_are_accessible
|
|
39
|
-
config.foo = "foo_value"
|
|
40
|
-
config.bar = "bar_value"
|
|
41
|
-
|
|
42
|
-
assert_equal(%w[foo bar], config.keys)
|
|
43
|
-
assert_equal(%w[foo_value bar_value], config.values)
|
|
44
|
-
|
|
45
|
-
ikeys = []
|
|
46
|
-
config.each_key { |k| ikeys << k }
|
|
47
|
-
assert_equal(%w[foo bar], ikeys)
|
|
48
|
-
|
|
49
|
-
ivalues = []
|
|
50
|
-
config.each_value { |v| ivalues << v }
|
|
51
|
-
assert_equal(%w[foo_value bar_value], ivalues)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_a_yml_file_can_be_loaded_by_env
|
|
55
|
-
config.load_yaml("example.yml")
|
|
56
|
-
assert_equal({ "foo" => "foo", "env_setting" => "setting_test" }, config.to_h)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def test_a_yml_file_can_be_loaded_by_raw
|
|
60
|
-
config.load_yaml("example.yml", ignore_env: true)
|
|
61
|
-
assert_equal({
|
|
62
|
-
"shared" => { "foo" => "foo" },
|
|
63
|
-
"production" => { "env_setting" => "setting_prod", "foo" => "foo" },
|
|
64
|
-
"test" => { "env_setting" => "setting_test", "foo" => "foo" },
|
|
65
|
-
}, config.to_h)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def test_a_yml_file_doesnt_load_with_additional_permitted_classes
|
|
69
|
-
assert_raises "Psych::DisallowedClass: Tried to load unspecified class: Symbol" do
|
|
70
|
-
config.load_yaml("example_with_symbols.yml", ignore_env: true)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def test_a_yml_file_can_be_loaded_with_additional_permitted_classes
|
|
75
|
-
config.load_yaml("example_with_symbols.yml", { permitted_classes: [Symbol] }, ignore_env: true)
|
|
76
|
-
assert_equal({
|
|
77
|
-
"shared" => { "foo" => :foo },
|
|
78
|
-
"production" => { "env_setting" => :setting_prod, "foo" => :foo },
|
|
79
|
-
"test" => { "env_setting" => :setting_test, "foo" => :foo },
|
|
80
|
-
}, config.to_h)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def test_top_level_configs_are_cached_in_root_namespace
|
|
84
|
-
::Confg.send :reset!
|
|
85
|
-
assert_equal({}, ::Confg.cache)
|
|
86
|
-
|
|
87
|
-
default_config = ::Confg.config(env: "test", root: "/")
|
|
88
|
-
custom_config = ::Confg.config(env: "foobar", root: "/Users/x/")
|
|
89
|
-
|
|
90
|
-
refute_equal default_config.object_id, custom_config.object_id
|
|
91
|
-
assert_equal 2, ::Confg.cache.size
|
|
92
|
-
assert_equal %w[test--/ foobar--/Users/x/], ::Confg.cache.keys
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
end
|
data/test/example.yml
DELETED