Skip to content

Commit

Permalink
Remove direct struct subclassing (#1491)
Browse files Browse the repository at this point in the history
This is a follow-up to 39f1b35 - I noticed I was still missing Faraday::Request#body= from Tapioca's generated definitions. Also did Faraday::Adapter::Test::Stub while we're here for consistency.
  • Loading branch information
bdewater committed Feb 8, 2023
1 parent 39f1b35 commit 450b0d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/faraday/adapter/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def matches?(stack, env)
end

# Stub request
class Stub < Struct.new(:host, :path, :query, :headers, :body, :strict_mode, :block) # rubocop:disable Style/StructInheritance
Stub = Struct.new(:host, :path, :query, :headers, :body, :strict_mode, :block) do
# @param env [Faraday::Env]
def matches?(env)
request_host = env[:url].host
Expand Down
15 changes: 8 additions & 7 deletions lib/faraday/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ module Faraday
# @return [String] body
# @!attribute options
# @return [RequestOptions] options
#
# rubocop:disable Style/StructInheritance
class Request < Struct.new(:http_method, :path, :params, :headers, :body, :options)
# rubocop:enable Style/StructInheritance

Request = Struct.new(:http_method, :path, :params, :headers, :body, :options) do
extend MiddlewareRegistry

alias_method :member_get, :[]
private :member_get
alias_method :member_set, :[]=
private :member_set

# @param request_method [String]
# @yield [request] for block customization, if block given
# @yieldparam request [Request]
Expand All @@ -48,7 +49,7 @@ def params=(hash)
if params
params.replace hash
else
super
member_set(:params, hash)
end
end

Expand All @@ -59,7 +60,7 @@ def headers=(hash)
if headers
headers.replace hash
else
super
member_set(:headers, hash)
end
end

Expand Down

0 comments on commit 450b0d9

Please sign in to comment.