lib/faraday/rack_builder.rb in faraday-1.0.1 vs lib/faraday/rack_builder.rb in faraday-1.1.0
- old
+ new
@@ -1,7 +1,8 @@
# frozen_string_literal: true
+require 'ruby2_keywords'
require 'faraday/adapter_registry'
module Faraday
# A Builder that processes requests into responses by passing through an inner
# middleware stack (heavily inspired by Rack).
@@ -25,11 +26,11 @@
class Handler
REGISTRY = Faraday::AdapterRegistry.new
attr_reader :name
- def initialize(klass, *args, &block)
+ ruby2_keywords def initialize(klass, *args, &block)
@name = klass.to_s
REGISTRY.set(klass) if klass.respond_to?(:name)
@args = args
@block = block
end
@@ -87,52 +88,52 @@
def locked?
@handlers.frozen?
end
- def use(klass, *args, &block)
+ ruby2_keywords def use(klass, *args, &block)
if klass.is_a? Symbol
use_symbol(Faraday::Middleware, klass, *args, &block)
else
raise_if_locked
raise_if_adapter(klass)
@handlers << self.class::Handler.new(klass, *args, &block)
end
end
- def request(key, *args, &block)
+ ruby2_keywords def request(key, *args, &block)
use_symbol(Faraday::Request, key, *args, &block)
end
- def response(key, *args, &block)
+ ruby2_keywords def response(key, *args, &block)
use_symbol(Faraday::Response, key, *args, &block)
end
- def adapter(klass = NO_ARGUMENT, *args, &block)
+ ruby2_keywords def adapter(klass = NO_ARGUMENT, *args, &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)
end
## methods to push onto the various positions in the stack:
- def insert(index, *args, &block)
+ ruby2_keywords def insert(index, *args, &block)
raise_if_locked
index = assert_index(index)
handler = self.class::Handler.new(*args, &block)
@handlers.insert(index, handler)
end
alias insert_before insert
- def insert_after(index, *args, &block)
+ ruby2_keywords def insert_after(index, *args, &block)
index = assert_index(index)
insert(index + 1, *args, &block)
end
- def swap(index, *args, &block)
+ ruby2_keywords def swap(index, *args, &block)
raise_if_locked
index = assert_index(index)
@handlers.delete_at(index)
insert(index, *args, &block)
end
@@ -184,11 +185,11 @@
def dup
self.class.new(@handlers.dup, @adapter.dup)
end
# ENV Keys
- # :method - a symbolized request method (:get, :post)
+ # :http_method - a symbolized request HTTP method (:get, :post)
# :body - the request body that will eventually be converted to a string.
# :url - URI instance for the current request.
# :status - HTTP response status code
# :request_headers - hash of HTTP Headers to be sent to the server
# :response_headers - Hash of HTTP headers from the server
@@ -205,11 +206,11 @@
exclusive_url = connection.build_exclusive_url(
request.path, request.params,
request.options.params_encoder
)
- Env.new(request.method, request.body, exclusive_url,
+ Env.new(request.http_method, request.body, exclusive_url,
request.options, request.headers, connection.ssl,
connection.parallel_manager)
end
private
@@ -229,13 +230,13 @@
def adapter_set?
!@adapter.nil?
end
def is_adapter?(klass) # rubocop:disable Naming/PredicateName
- klass.ancestors.include?(Faraday::Adapter)
+ klass <= Faraday::Adapter
end
- def use_symbol(mod, key, *args, &block)
+ ruby2_keywords def use_symbol(mod, key, *args, &block)
use(mod.lookup_middleware(key), *args, &block)
end
def assert_index(index)
idx = index.is_a?(Integer) ? index : @handlers.index(index)