Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use argument forwarding operator for add_provider #2

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.3', '2.7', '3.0', '3.1']
ruby-version: ['2.7', '3.0', '3.1', '3.2']
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ your default settings with a user configuration file and let those be overridden
by environment variables. The query interface allows to group and nest your configuration options
to a practically unlimited level.

Configurate supports Ruby 2.3 or later.
Configurate supports Ruby 2.7 or later.

## Installation

Expand Down
2 changes: 1 addition & 1 deletion configurate.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |s|
s.test_files = Dir["spec/**/*.rb"]
s.require_paths = ["lib"]

s.required_ruby_version = ">= 2.3.0"
s.required_ruby_version = ">= 2.7.0"

s.add_development_dependency "rake", ">= 10.0.3"
s.add_development_dependency "rspec", ">= 3.0"
Expand Down
10 changes: 5 additions & 5 deletions lib/configurate/lookup_chain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def initialize
# they are added, so the order is important.
#
# @param provider [#lookup]
# @param *args the arguments passed to the providers constructor
# @param ... the arguments passed to the providers constructor
# @raise [ArgumentError] if an invalid provider is given
# @return [void]
def add_provider(provider, *args)
def add_provider(provider, ...)
unless provider.respond_to?(:instance_methods) && provider.instance_methods.include?(:lookup)
raise ArgumentError, "the given provider does not respond to lookup"
end

@provider << provider.new(*args)
@provider << provider.new(...)
end

# Tries all providers in the order they were added to provide a response
Expand All @@ -31,11 +31,11 @@ def add_provider(provider, *args)
# @param ... further args passed to the provider
# @return [Array,Hash,String,Boolean,nil] whatever the responding
# provider provides is casted to a {String}, except for some special values
def lookup(setting, *args)
def lookup(setting, ...)
setting = SettingPath.new setting if setting.is_a? String
@provider.each do |provider|
begin
return special_value_or_string(provider.lookup(setting.clone, *args))
return special_value_or_string(provider.lookup(setting.clone, ...))
rescue SettingNotFoundError; end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/configurate/lookup_chain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def lookup(_setting, *_args); end
expect(ValidConfigurationProvider).to receive(:new).with(:extra)
subject.add_provider ValidConfigurationProvider, :extra
end

it "passes keyword args to the provider" do
expect(ValidConfigurationProvider).to receive(:new).with(required: false)
subject.add_provider ValidConfigurationProvider, required: false
end
end

describe "#lookup" do
Expand Down