Skip to content

Commit 2477fe2

Browse files
committed
Remove direct struct subclassing
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.
1 parent 39f1b35 commit 2477fe2

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/faraday/adapter/test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def matches?(stack, env)
184184
end
185185

186186
# Stub request
187-
class Stub < Struct.new(:host, :path, :query, :headers, :body, :strict_mode, :block) # rubocop:disable Style/StructInheritance
187+
Stub = Struct.new(:host, :path, :query, :headers, :body, :strict_mode, :block) do
188188
# @param env [Faraday::Env]
189189
def matches?(env)
190190
request_host = env[:url].host

lib/faraday/request.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ module Faraday
2424
# @return [String] body
2525
# @!attribute options
2626
# @return [RequestOptions] options
27-
#
28-
# rubocop:disable Style/StructInheritance
29-
class Request < Struct.new(:http_method, :path, :params, :headers, :body, :options)
30-
# rubocop:enable Style/StructInheritance
31-
27+
Request = Struct.new(:http_method, :path, :params, :headers, :body, :options) do
3228
extend MiddlewareRegistry
3329

30+
alias_method :member_get, :[]
31+
private :member_get
32+
alias_method :member_set, :[]=
33+
private :member_set
34+
3435
# @param request_method [String]
3536
# @yield [request] for block customization, if block given
3637
# @yieldparam request [Request]
@@ -48,7 +49,7 @@ def params=(hash)
4849
if params
4950
params.replace hash
5051
else
51-
super
52+
member_set(:params, hash)
5253
end
5354
end
5455

@@ -59,7 +60,7 @@ def headers=(hash)
5960
if headers
6061
headers.replace hash
6162
else
62-
super
63+
member_set(:headers, hash)
6364
end
6465
end
6566

0 commit comments

Comments
 (0)