Skip to content

Commit 33a7e7c

Browse files
committed
feat: refactor request method handling by introducing RequestMethod module
1 parent 2efdf11 commit 33a7e7c

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

lib/rubocop-committee.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require_relative "rubocop/committee/version"
66
require_relative "rubocop/committee/plugin"
77

8+
require_relative "rubocop/committee/request_method"
89
require_relative "rubocop/cop/committee/assert_schema_conform_without_request"
910
require_relative "rubocop/cop/committee/deprecated_old_assert_behavior"
1011
require_relative "rubocop/cop/committee/multiple_schema_conform"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
module RuboCop
4+
module Committee
5+
module RequestMethod
6+
METHODS = %i[get post put patch delete head options].freeze
7+
8+
def self.call?(send_node)
9+
send_node.receiver.nil? && METHODS.include?(send_node.method_name)
10+
end
11+
end
12+
end
13+
end

lib/rubocop/cop/committee/assert_schema_conform_without_request.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module Committee
2020
class AssertSchemaConformWithoutRequest < Base
2121
MSG = "Call an HTTP request method before asserting schema conformance."
2222

23-
REQUEST_METHODS = %i[get post put patch delete head options].freeze
2423
ASSERT_METHODS = %i[
2524
assert_schema_conform
2625
assert_request_schema_confirm
@@ -114,7 +113,7 @@ def example_group_block?(node)
114113
end
115114

116115
def request_method?(send_node)
117-
send_node.receiver.nil? && REQUEST_METHODS.include?(send_node.method_name)
116+
::RuboCop::Committee::RequestMethod.call?(send_node)
118117
end
119118
end
120119
end

lib/rubocop/cop/committee/multiple_schema_conform.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class MultipleSchemaConform < Base
2727
assert_request_schema_confirm
2828
assert_response_schema_confirm
2929
].freeze
30-
REQUEST_METHODS = %i[get post put patch delete head options].freeze
3130
EXAMPLE_METHODS = %i[it specify example scenario].freeze
3231

3332
RESTRICT_ON_SEND = ASSERT_METHODS
@@ -80,7 +79,7 @@ def request_segments(example_block)
8079
def request_call?(node)
8180
return false unless node&.send_type?
8281

83-
node.receiver.nil? && REQUEST_METHODS.include?(node.method_name)
82+
::RuboCop::Committee::RequestMethod.call?(node)
8483
end
8584

8685
def segment_for(node, segments)

0 commit comments

Comments
 (0)