Class: RuboCop::Cop::Iotventure::DuplicateResponseCode
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Iotventure::DuplicateResponseCode
- Defined in:
- lib/rubocop/cop/iotventure/duplicate_response_code.rb
Overview
This cop checks for duplicated response code example definitions.
Constant Summary collapse
- DUPLICATE_MSG =
'Response Code `%<response_code>s` is defined at both %<other>s and %<current>s.'
- IN_LOOP_MSG =
'Response definition at %<current>s is defined inside loop at %<loop>s'
Instance Method Summary collapse
-
#initialize(config = nil, options = nil) ⇒ DuplicateResponseCode
constructor
A new instance of DuplicateResponseCode.
- #on_block(node) ⇒ Object
- #response_code_definition?(node) ⇒ Object
- #route_definition?(node) ⇒ Object
Constructor Details
#initialize(config = nil, options = nil) ⇒ DuplicateResponseCode
Returns a new instance of DuplicateResponseCode.
75 76 77 78 |
# File 'lib/rubocop/cop/iotventure/duplicate_response_code.rb', line 75 def initialize(config = nil, = nil) super @definitions = {} end |
Instance Method Details
#on_block(node) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/rubocop/cop/iotventure/duplicate_response_code.rb', line 80 def on_block(node) code = response_code_definition(node) return unless code check_for_duplicate_response_code(node, code) check_for_definition_inside_loop(node) end |
#response_code_definition?(node) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/rubocop/cop/iotventure/duplicate_response_code.rb', line 58 def_node_matcher :response_code_definition, <<~PATTERN (block (send nil? :response (int $_) ...) ... ) PATTERN |
#route_definition?(node) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/rubocop/cop/iotventure/duplicate_response_code.rb', line 68 def_node_matcher :route_definition, <<~PATTERN (block (send nil? #route_verb? (str _)) ... ) PATTERN |