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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ffa65a341a5ea7d93390edf845981fd50c0df586c6e28b7c8487b035706092a
4
- data.tar.gz: c5bba8919704165a458b2509a75f83ef10b1c5eb9056a39aa53368e7f6a19a2a
3
+ metadata.gz: 1a8d68f7467992b67e6498153d220d203432287054549f768546f70127e6923f
4
+ data.tar.gz: add43866b97a32d137455b63a79778669310fda072ecb79d6f22937fef0b17c6
5
5
  SHA512:
6
- metadata.gz: f15b35166baaaf7270a755a6770839c774cb581052004aac9b4f85a1d0e333a52eec9c0a8ea0d577d96bf8028f1c1a63106c0a7cf21eb47016787d5b7d64f53c
7
- data.tar.gz: 9b28f027b6aab53c8ff152faafc932ad01767fe64f5de95ec84839956d54e393cf743b92171a0120f36d36f01611b2dc0dc4cb7cd3def5fb68414687d3bfcff2
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
@@ -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
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Confg
4
4
 
5
- VERSION = "3.0.1"
5
+ MAJOR = 3
6
+ MINOR = 3
7
+ PATCH = 0
8
+ PRERELEASE = nil
6
9
 
10
+ VERSION = [MAJOR, MINOR, PATCH, PRERELEASE].compact.join(".")
7
11
  end
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.1
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: 2023-09-13 00:00:00.000000000 Z
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
- - test/confg_test.rb
87
- - test/example.yml
88
- - test/example_with_symbols.yml
89
- - test/test_helper.rb
90
- homepage: ''
91
- licenses: []
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: '0'
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.33
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
@@ -1,17 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
15
- *.gem
16
- .byebug_history
17
- /vendor/
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 3.0.6
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in config.gemspec
4
- gemspec
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
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/*_test.rb"]
10
- end
11
-
12
- task default: :test
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
@@ -1,10 +0,0 @@
1
- shared: &shared
2
- foo: "foo"
3
-
4
- production:
5
- <<: *shared
6
- env_setting: "setting_prod"
7
-
8
- test:
9
- <<: *shared
10
- env_setting: "setting_test"
@@ -1,10 +0,0 @@
1
- shared: &shared
2
- foo: :foo
3
-
4
- production:
5
- <<: *shared
6
- env_setting: :setting_prod
7
-
8
- test:
9
- <<: *shared
10
- env_setting: :setting_test
data/test/test_helper.rb DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
- require "confg"
5
-
6
- require "minitest/autorun"