configurate 0.4.0 → 0.6.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: c7ee31139c43b2f17023d605dee685f0618fcc0e56b068733cddb8e5e10cf006
4
- data.tar.gz: 5ee1c764538c194795750718c6a530cbd94684d334782afc7fa47a35083547af
3
+ metadata.gz: c6cbde7141caa3d2c774fff3a2cc73174410582d050682b5d4804870af484b07
4
+ data.tar.gz: 29daacb8ee699fe7ab37d320f78f9fb5a2722c825b28dac9077cd50ce9abc383
5
5
  SHA512:
6
- metadata.gz: c221bc2ed5cf3b7705a207776628621301cd73c3e891dac13ba9d2ada574fc265a5678edff29974da657daa373d712ccb6753ee2083ad6ab0d94b36cd1314225
7
- data.tar.gz: 338aaf220e3ccc945a35079fb15c50c6af87132c78c97fb7fe0ff1d2d8bdd54e5a0406aa01d890eb910cfee55fb649667e67c042c54e005d0772ce654ba9be1a
6
+ metadata.gz: 15bc4f73d51fa365b6de1386f73d3cd92aaf72bdb9bed931c75a7046ca7a79a15beb43f0315d8db5f4d0d628c27b8e533fbadd063b1c2898f36dd0e89e23e563
7
+ data.tar.gz: b5e8260b309c38f58479590b07c849889c227ff51b5fd5945e689f768b0b0f69ded625c6b5fb89eabdd380c1647ce7f2c2dd3d539f9e3a45a69f31f8ca56ab27
data/Changelog.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 0.6.0
2
+
3
+ * Add support for Ruby 3.2
4
+ * Drop support for Ruby below 2.7
5
+
6
+ # 0.5.0
7
+
8
+ * Support and prefer `toml-rb` over `tomlrb` in the shipped TOML provider.
9
+ * Drop explicit support for Ruby < 2.4
10
+
1
11
  # 0.4.0
2
12
 
3
13
  * `Configurate::Proxy` returns its own singleton class if the target does not support creating one.
data/README.md CHANGED
@@ -10,7 +10,7 @@ your default settings with a user configuration file and let those be overridden
10
10
  by environment variables. The query interface allows to group and nest your configuration options
11
11
  to a practically unlimited level.
12
12
 
13
- Configurate supports Ruby 2.0 or later.
13
+ Configurate supports Ruby 2.7 or later.
14
14
 
15
15
  ## Installation
16
16
 
@@ -137,8 +137,8 @@ Config.stuff.param # => "foo"
137
137
  Config.stuff.nested.param # => "bar"
138
138
  ```
139
139
 
140
- This provider depends on the [tomlrb](https://github.com/fbernier/tomlrb) gem. This is why it is not loaded by default and
141
- needs an explicit `require 'configurate/provider/toml' to be available.
140
+ This provider depends on the [toml-rb](https://github.com/emancu/toml-rb) or the [tomlrb](https://github.com/fbernier/tomlrb) gem.
141
+ This is why it is not loaded by default and needs an explicit `require 'configurate/provider/toml'` to be available. If both are available, toml-rb is preferred.
142
142
 
143
143
  The initializer takes a path to the configuration file a the mandatory first argument and
144
144
  the following optional parameters:
@@ -12,15 +12,15 @@ module Configurate
12
12
  # they are added, so the order is important.
13
13
  #
14
14
  # @param provider [#lookup]
15
- # @param *args the arguments passed to the providers constructor
15
+ # @param ... the arguments passed to the providers constructor
16
16
  # @raise [ArgumentError] if an invalid provider is given
17
17
  # @return [void]
18
- def add_provider(provider, *args)
18
+ def add_provider(provider, ...)
19
19
  unless provider.respond_to?(:instance_methods) && provider.instance_methods.include?(:lookup)
20
20
  raise ArgumentError, "the given provider does not respond to lookup"
21
21
  end
22
22
 
23
- @provider << provider.new(*args)
23
+ @provider << provider.new(...)
24
24
  end
25
25
 
26
26
  # Tries all providers in the order they were added to provide a response
@@ -31,11 +31,11 @@ module Configurate
31
31
  # @param ... further args passed to the provider
32
32
  # @return [Array,Hash,String,Boolean,nil] whatever the responding
33
33
  # provider provides is casted to a {String}, except for some special values
34
- def lookup(setting, *args)
34
+ def lookup(setting, ...)
35
35
  setting = SettingPath.new setting if setting.is_a? String
36
36
  @provider.each do |provider|
37
37
  begin
38
- return special_value_or_string(provider.lookup(setting.clone, *args))
38
+ return special_value_or_string(provider.lookup(setting.clone, ...))
39
39
  rescue SettingNotFoundError; end
40
40
  end
41
41
 
@@ -1,13 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "configurate"
4
- require "tomlrb"
5
4
 
6
5
  module Configurate
7
6
  module Provider
8
7
  # This provider tries to open a TOML file and does nested lookups
9
8
  # in it.
10
9
  class TOML < StringHash
10
+ begin
11
+ require "toml-rb"
12
+ PARSER = TomlRB
13
+ rescue LoadError => e
14
+ require "tomlrb"
15
+ PARSER = Tomlrb
16
+ end
17
+
11
18
  # @param file [String] the path to the file
12
19
  # @param namespace [String] optionally set this as the root
13
20
  # @param required [Boolean] whether or not to raise an error if
@@ -17,7 +24,7 @@ module Configurate
17
24
  # @raise [ArgumentError] if the namespace isn't found in the file
18
25
  # @raise [Errno:ENOENT] if the file isn't found
19
26
  def initialize file, namespace: nil, required: true, raise_on_missing: false
20
- super(Tomlrb.load_file(file),
27
+ super(PARSER.load_file(file),
21
28
  namespace: namespace,
22
29
  required: required,
23
30
  raise_on_missing: raise_on_missing,
@@ -27,6 +27,11 @@ describe Configurate::LookupChain do
27
27
  expect(ValidConfigurationProvider).to receive(:new).with(:extra)
28
28
  subject.add_provider ValidConfigurationProvider, :extra
29
29
  end
30
+
31
+ it "passes keyword args to the provider" do
32
+ expect(ValidConfigurationProvider).to receive(:new).with(required: false)
33
+ subject.add_provider ValidConfigurationProvider, required: false
34
+ end
30
35
  end
31
36
 
32
37
  describe "#lookup" do
@@ -4,6 +4,8 @@ require "spec_helper"
4
4
  require "configurate/provider/toml"
5
5
 
6
6
  describe Configurate::Provider::TOML do
7
+ PARSER = Configurate::Provider::TOML::PARSER
8
+
7
9
  let(:settings) {
8
10
  {
9
11
  "toplevel" => "bar",
@@ -16,12 +18,12 @@ describe Configurate::Provider::TOML do
16
18
  describe "#initialize" do
17
19
  it "loads the file" do
18
20
  file = "foobar.toml"
19
- expect(Tomlrb).to receive(:load_file).with(file).and_return({})
21
+ expect(PARSER).to receive(:load_file).with(file).and_return({})
20
22
  described_class.new file
21
23
  end
22
24
 
23
25
  it "raises if the file is not found" do
24
- allow(Tomlrb).to receive(:load_file).and_raise(Errno::ENOENT)
26
+ allow(PARSER).to receive(:load_file).and_raise(Errno::ENOENT)
25
27
  expect {
26
28
  silence_stderr do
27
29
  described_class.new "foo"
@@ -32,13 +34,13 @@ describe Configurate::Provider::TOML do
32
34
  context "with a namespace" do
33
35
  it "looks in the file for that namespace" do
34
36
  namespace = "some.nested"
35
- allow(Tomlrb).to receive(:load_file).and_return(settings)
37
+ allow(PARSER).to receive(:load_file).and_return(settings)
36
38
  provider = described_class.new "bla", namespace: namespace
37
39
  expect(provider.instance_variable_get(:@settings)).to eq settings["some"]["nested"]
38
40
  end
39
41
 
40
42
  it "raises if the namespace isn't found" do
41
- allow(Tomlrb).to receive(:load_file).and_return({})
43
+ allow(PARSER).to receive(:load_file).and_return({})
42
44
  expect {
43
45
  silence_stderr do
44
46
  described_class.new "bla", namespace: "bar"
@@ -47,7 +49,7 @@ describe Configurate::Provider::TOML do
47
49
  end
48
50
 
49
51
  it "works with an empty namespace in the file" do
50
- allow(Tomlrb).to receive(:load_file).and_return("foo" => {"bar" => nil})
52
+ allow(PARSER).to receive(:load_file).and_return("foo" => {"bar" => nil})
51
53
  expect {
52
54
  silence_stderr do
53
55
  described_class.new "bla", namespace: "foo.bar"
@@ -58,7 +60,7 @@ describe Configurate::Provider::TOML do
58
60
 
59
61
  context "with required set to false" do
60
62
  it "doesn't raise if a file isn't found" do
61
- allow(Tomlrb).to receive(:load_file).and_raise(Errno::ENOENT)
63
+ allow(PARSER).to receive(:load_file).and_raise(Errno::ENOENT)
62
64
  expect {
63
65
  silence_stderr do
64
66
  described_class.new "not_me", required: false
@@ -67,7 +69,7 @@ describe Configurate::Provider::TOML do
67
69
  end
68
70
 
69
71
  it "doesn't raise if a namespace isn't found" do
70
- allow(Tomlrb).to receive(:load_file).and_return({})
72
+ allow(PARSER).to receive(:load_file).and_return({})
71
73
  expect {
72
74
  silence_stderr do
73
75
  described_class.new "bla", namespace: "foo", required: false
@@ -79,7 +81,7 @@ describe Configurate::Provider::TOML do
79
81
 
80
82
  describe "#lookup_path" do
81
83
  before do
82
- allow(Tomlrb).to receive(:load_file).and_return(settings)
84
+ allow(PARSER).to receive(:load_file).and_return(settings)
83
85
  @provider = described_class.new "dummy"
84
86
  end
85
87
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configurate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonne Haß
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2023-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: tomlrb
42
+ name: toml-rb
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.3.0
47
+ version: 2.0.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.3.0
54
+ version: 2.0.1
55
55
  description: Configurate is a flexible configuration system that can read settings
56
56
  from multiple sources at the same time.
57
57
  email: me@jhass.eu
@@ -87,7 +87,7 @@ homepage: http://jhass.github.io/configurate
87
87
  licenses:
88
88
  - MIT
89
89
  metadata: {}
90
- post_install_message:
90
+ post_install_message:
91
91
  rdoc_options: []
92
92
  require_paths:
93
93
  - lib
@@ -95,26 +95,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - ">="
97
97
  - !ruby/object:Gem::Version
98
- version: 2.0.0
98
+ version: 2.7.0
99
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubygems_version: 3.1.2
106
- signing_key:
105
+ rubygems_version: 3.4.13
106
+ signing_key:
107
107
  specification_version: 4
108
108
  summary: Flexbile configuration system
109
109
  test_files:
110
- - spec/spec_helper.rb
111
110
  - spec/configurate/lookup_chain_spec.rb
112
- - spec/configurate/provider/toml_spec.rb
113
111
  - spec/configurate/provider/dynamic_spec.rb
114
- - spec/configurate/provider/yaml_spec.rb
115
- - spec/configurate/provider/string_hash_spec.rb
116
112
  - spec/configurate/provider/env_spec.rb
117
- - spec/configurate/proxy_spec.rb
113
+ - spec/configurate/provider/string_hash_spec.rb
114
+ - spec/configurate/provider/toml_spec.rb
115
+ - spec/configurate/provider/yaml_spec.rb
118
116
  - spec/configurate/provider_spec.rb
117
+ - spec/configurate/proxy_spec.rb
119
118
  - spec/configurate/setting_path_spec.rb
120
119
  - spec/configurate_spec.rb
120
+ - spec/spec_helper.rb