Class: RuboCop::Cop::Netlify::RequireScopeBase

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/netlify/require_scope_base.rb

Constant Summary collapse

RESTRICT_ON_SEND =
[:require_scope, :public, :private, :protected]

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



9
10
11
12
13
# File 'lib/rubocop/cop/netlify/require_scope_base.rb', line 9

def on_class(node)
  @require_scopes = []
  @method_protection = :public
  @is_controller = node.identifier.short_name.to_s.end_with?("Controller")
end

#on_send(node) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubocop/cop/netlify/require_scope_base.rb', line 15

def on_send(node)
  if node.method_name == :require_scope
    scopes = []
    limits = {}
    node.arguments.each do |option|
      if option.is_a? RuboCop::AST::StrNode
        scopes << option.value
      elsif option.is_a? RuboCop::AST::HashNode
        option.pairs.each do |pair|
          if pair.value.is_a? RuboCop::AST::ArrayNode
            limits[pair.key.value] = pair.value.values.map(&:value)
          elsif pair.value.is_a? RuboCop::AST::SymbolNode
            limits[pair.key.value] = [pair.value.value]
          end
        end
      end
    end

    @require_scopes << {
      scopes: scopes,
      limits: limits,
      node: node
    }
  else
    @method_protection = node.method_name
  end
end