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

avoid argument warnings / prepare for ruby 3 #1209

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion faraday.gemspec
Expand Up @@ -16,7 +16,6 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.4'

spec.add_dependency 'multipart-post', '>= 1.2', '< 3'
spec.add_dependency 'ruby2_keywords'

# Includes `examples` and `spec` to allow external adapter gems to run Faraday unit and integration tests
spec.files = Dir['CHANGELOG.md', '{examples,lib,spec}/**/*', 'LICENSE.md', 'Rakefile', 'README.md']
Expand Down
40 changes: 20 additions & 20 deletions lib/faraday/rack_builder.rb
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'ruby2_keywords'
require 'faraday/adapter_registry'

module Faraday
Expand Down Expand Up @@ -28,10 +27,11 @@ class Handler

attr_reader :name

ruby2_keywords def initialize(klass, *args, &block)
def initialize(klass, *args, **kwargs, &block)
@name = klass.to_s
REGISTRY.set(klass) if klass.respond_to?(:name)
@args = args
@kwargs = kwargs
@block = block
end

Expand All @@ -54,7 +54,7 @@ def ==(other)
end

def build(app = nil)
klass.new(app, *@args, &@block)
klass.new(app, *@args, **@kwargs, &@block)
end
end

Expand Down Expand Up @@ -90,52 +90,52 @@ def locked?
@handlers.frozen?
end

ruby2_keywords def use(klass, *args, &block)
def use(klass, *args, **kwargs, &block)
if klass.is_a? Symbol
use_symbol(Faraday::Middleware, klass, *args, &block)
use_symbol(Faraday::Middleware, klass, *args, **kwargs, &block)
else
raise_if_locked
raise_if_adapter(klass)
@handlers << self.class::Handler.new(klass, *args, &block)
@handlers << self.class::Handler.new(klass, *args, **kwargs, &block)
end
end

ruby2_keywords def request(key, *args, &block)
use_symbol(Faraday::Request, key, *args, &block)
def request(key, *args, **kwargs, &block)
use_symbol(Faraday::Request, key, *args, **kwargs, &block)
end

ruby2_keywords def response(key, *args, &block)
use_symbol(Faraday::Response, key, *args, &block)
def response(key, *args, **kwargs, &block)
use_symbol(Faraday::Response, key, *args, **kwargs, &block)
end

ruby2_keywords def adapter(klass = NO_ARGUMENT, *args, &block)
def adapter(klass = NO_ARGUMENT, *args, **kwargs, &block)
return @adapter if klass == NO_ARGUMENT

klass = Faraday::Adapter.lookup_middleware(klass) if klass.is_a?(Symbol)
@adapter = self.class::Handler.new(klass, *args, &block)
@adapter = self.class::Handler.new(klass, *args, **kwargs, &block)
end

## methods to push onto the various positions in the stack:

ruby2_keywords def insert(index, *args, &block)
def insert(index, *args, **kwargs, &block)
raise_if_locked
index = assert_index(index)
handler = self.class::Handler.new(*args, &block)
handler = self.class::Handler.new(*args, **kwargs, &block)
@handlers.insert(index, handler)
end

alias insert_before insert

ruby2_keywords def insert_after(index, *args, &block)
def insert_after(index, *args, **kwargs, &block)
index = assert_index(index)
insert(index + 1, *args, &block)
insert(index + 1, *args, **kwargs, &block)
end

ruby2_keywords def swap(index, *args, &block)
def swap(index, *args, **kwargs, &block)
raise_if_locked
index = assert_index(index)
@handlers.delete_at(index)
insert(index, *args, &block)
insert(index, *args, **kwargs, &block)
end

def delete(handler)
Expand Down Expand Up @@ -235,8 +235,8 @@ def is_adapter?(klass) # rubocop:disable Naming/PredicateName
klass <= Faraday::Adapter
end

ruby2_keywords def use_symbol(mod, key, *args, &block)
use(mod.lookup_middleware(key), *args, &block)
def use_symbol(mod, key, *args, **kwargs, &block)
use(mod.lookup_middleware(key), *args, **kwargs, &block)
end

def assert_index(index)
Expand Down