mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
removing a few method_missing implementations
replacing them with SimpleDelegator where it made sense, and removing them altogether whenever possible. ErrorResponse doesn't have a special handling for Response methods anymore, but it's highly debatable if it should.
This commit is contained in:
parent
15143f7322
commit
7aea7fe471
@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "delegate"
|
||||
require "httpx"
|
||||
require "faraday"
|
||||
|
||||
@ -91,11 +92,12 @@ module Faraday
|
||||
end
|
||||
|
||||
class ParallelManager
|
||||
class ResponseHandler
|
||||
class ResponseHandler < SimpleDelegator
|
||||
attr_reader :env
|
||||
|
||||
def initialize(env)
|
||||
@env = env
|
||||
super
|
||||
end
|
||||
|
||||
def on_response(&blk)
|
||||
@ -117,16 +119,6 @@ module Faraday
|
||||
@on_complete
|
||||
end
|
||||
end
|
||||
|
||||
def respond_to_missing?(meth)
|
||||
@env.respond_to?(meth) || super
|
||||
end
|
||||
|
||||
def method_missing(meth, *args, &blk)
|
||||
return super unless @env && @env.respond_to?(meth)
|
||||
|
||||
@env.__send__(meth, *args, &blk)
|
||||
end
|
||||
end
|
||||
|
||||
include RequestMixin
|
||||
|
@ -79,7 +79,11 @@ module HTTPX
|
||||
end
|
||||
|
||||
def respond_to_missing?(meth)
|
||||
default_options.respond_to?(meth) || super
|
||||
return super unless meth =~ /\Awith_(.+)/
|
||||
|
||||
option = Regexp.last_match(1)
|
||||
|
||||
default_options.respond_to?(option) || super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -391,16 +391,6 @@ module HTTPX
|
||||
emit(:pong)
|
||||
end
|
||||
end
|
||||
|
||||
def respond_to_missing?(meth, *args)
|
||||
@connection.respond_to?(meth, *args) || super
|
||||
end
|
||||
|
||||
def method_missing(meth, *args, &blk)
|
||||
return super unless @connection.respond_to?(meth)
|
||||
|
||||
@connection.__send__(meth, *args, &blk)
|
||||
end
|
||||
end
|
||||
Connection.register "h2", Connection::HTTP2
|
||||
end
|
||||
|
@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "delegate"
|
||||
require "forwardable"
|
||||
|
||||
module HTTPX
|
||||
@ -155,7 +156,7 @@ module HTTPX
|
||||
end
|
||||
# :nocov:
|
||||
|
||||
class Body
|
||||
class Body < SimpleDelegator
|
||||
class << self
|
||||
def new(*, options)
|
||||
return options.body if options.body.is_a?(self)
|
||||
@ -177,6 +178,7 @@ module HTTPX
|
||||
|
||||
@headers["content-type"] ||= @body.content_type
|
||||
@headers["content-length"] = @body.bytesize unless unbounded_body?
|
||||
super(@body)
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
@ -238,16 +240,6 @@ module HTTPX
|
||||
"#{unbounded_body? ? "stream" : "@bytesize=#{bytesize}"}>"
|
||||
end
|
||||
# :nocov:
|
||||
|
||||
def respond_to_missing?(meth, *args)
|
||||
@body.respond_to?(meth, *args) || super
|
||||
end
|
||||
|
||||
def method_missing(meth, *args, &block)
|
||||
return super unless @body.respond_to?(meth)
|
||||
|
||||
@body.__send__(meth, *args, &block)
|
||||
end
|
||||
end
|
||||
|
||||
def transition(nextstate)
|
||||
|
@ -286,14 +286,6 @@ module HTTPX
|
||||
def raise_for_status
|
||||
raise @error
|
||||
end
|
||||
|
||||
# rubocop:disable Style/MissingRespondToMissing
|
||||
def method_missing(meth, *, &block)
|
||||
raise NoMethodError, "undefined response method `#{meth}' for error response" if @options.response_class.public_method_defined?(meth)
|
||||
|
||||
super
|
||||
end
|
||||
# rubocop:enable Style/MissingRespondToMissing
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -16,14 +16,6 @@ class ErrorResponseTest < Minitest::Test
|
||||
assert_raises(some_error) { r1.raise_for_status }
|
||||
end
|
||||
|
||||
def test_error_response_respond_method_missing_errors
|
||||
r1 = ErrorResponse.new(request_mock, RuntimeError.new("wow"), {})
|
||||
ex1 = assert_raises(NoMethodError) { r1.read }
|
||||
assert ex1.message =~ /undefined response method/
|
||||
ex2 = assert_raises(NoMethodError) { r1.bang }
|
||||
assert ex2.message =~ /undefined method/
|
||||
end
|
||||
|
||||
def test_error_response_to_s
|
||||
r = ErrorResponse.new(request_mock, RuntimeError.new("wow"), {})
|
||||
str = r.to_s
|
||||
|
@ -12,7 +12,7 @@ module SessionWithSingleStream
|
||||
@connection.active_stream_count.positive?
|
||||
end
|
||||
parser.instance_variable_set(:@max_requests, 10)
|
||||
parser.max_streams = 1
|
||||
parser.instance_variable_get(:@connection).max_streams = 1
|
||||
parser
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user