module RuboCop::Cop::AccessModifierNode

Common functionality for checking modifier nodes.

Constants

MODULE_FUNCTION_NODE
PRIVATE_NODE
PROTECTED_NODE
PUBLIC_NODE

Public Instance Methods

class_or_module_parent?(node) click to toggle source

Returns true when the parent of what looks like an access modifier is a Class or Module. Filters out simple method calls to similarly named private, protected or public.

# File lib/rubocop/cop/mixin/access_modifier_node.rb, line 30
def class_or_module_parent?(node)
  node.each_ancestor do |a|
    if a.type == :block
      return true if a.class_constructor?
    elsif a.type != :begin
      return [:casgn, :sclass, :class, :module].include?(a.type)
    end
  end
end
modifier_node?(node) click to toggle source

Returns true when the node is an access modifier.

# File lib/rubocop/cop/mixin/access_modifier_node.rb, line 15
def modifier_node?(node)
  modifier_structure?(node) && class_or_module_parent?(node)
end
modifier_structure?(node) click to toggle source

Returns true when the node looks like an access modifier.

# File lib/rubocop/cop/mixin/access_modifier_node.rb, line 20
def modifier_structure?(node)
  [PRIVATE_NODE,
   PROTECTED_NODE,
   PUBLIC_NODE,
   MODULE_FUNCTION_NODE].include?(node)
end