Module: RuboCop::Cop::AccessModifierNode
- Extended by:
- Sexp
- Included in:
- Style::AccessModifierIndentation, Style::EmptyLinesAroundAccessModifier, Style::IndentationConsistency, Style::IndentationWidth
- Defined in:
- lib/rubocop/cop/mixin/access_modifier_node.rb
Overview
Common functionality for checking modifier nodes.
Constant Summary collapse
- PRIVATE_NODE =
s(:send, nil, :private)
- PROTECTED_NODE =
s(:send, nil, :protected)
- PUBLIC_NODE =
s(:send, nil, :public)
- MODULE_FUNCTION_NODE =
s(:send, nil, :module_function)
Instance Method Summary collapse
-
#class_or_module_parent?(node) ⇒ Boolean
Returns true when the parent of what looks like an access modifier is a Class or Module.
-
#modifier_node?(node) ⇒ Boolean
Returns true when the node is an access modifier.
-
#modifier_structure?(node) ⇒ Boolean
Returns true when the node looks like an access modifier.
Methods included from Sexp
Instance Method Details
#class_or_module_parent?(node) ⇒ Boolean
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.
31 32 33 34 35 36 37 38 39 |
# File 'lib/rubocop/cop/mixin/access_modifier_node.rb', line 31 def class_or_module_parent?(node) node.each_ancestor do |ancestor| if ancestor.block_type? return true if ancestor.class_constructor? elsif !ancestor.begin_type? return [:casgn, :sclass, :class, :module].include?(ancestor.type) end end end |
#modifier_node?(node) ⇒ Boolean
Returns true when the node is an access modifier.
16 17 18 |
# File 'lib/rubocop/cop/mixin/access_modifier_node.rb', line 16 def modifier_node?(node) modifier_structure?(node) && class_or_module_parent?(node) end |
#modifier_structure?(node) ⇒ Boolean
Returns true when the node looks like an access modifier.
21 22 23 24 25 26 |
# File 'lib/rubocop/cop/mixin/access_modifier_node.rb', line 21 def modifier_structure?(node) [PRIVATE_NODE, PROTECTED_NODE, PUBLIC_NODE, MODULE_FUNCTION_NODE].include?(node) end |