Class: RuboCop::Cop::Rails::CollectionContext

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/shared/collection_context.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

ROUTE_CATEGORIES =
{
  simple: [:get, :post, :put, :patch, :delete, :head, :options, :match, :root],
  resource: [:resource, :resources],
  namespace: [:namespace, :scope, :concern, :member, :collection],
  draw: [:draw]
}.freeze
ALL_ROUTE_METHODS =
ROUTE_CATEGORIES.values.flatten.freeze
SCOPE_OPTIONS =
[:module, :path].freeze

Instance Method Summary collapse

Constructor Details

#initialize(collector, namespace_level, namespace_path = []) ⇒ CollectionContext



17
18
19
20
21
# File 'lib/rubocop/cop/shared/collection_context.rb', line 17

def initialize(collector, namespace_level, namespace_path = [])
  @collector = collector
  @namespace_level = namespace_level
  @namespace_path = namespace_path
end

Instance Method Details

#process_node(node) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/rubocop/cop/shared/collection_context.rb', line 23

def process_node(node)
  case node.type
  when :begin
    node.children.each { |child| process_node(child) }
  when :send
    add_route_if_valid(node)
  when :block
    process_block(node)
  end
end