123456789_123456789_123456789_123456789_123456789_

Module: RuboCop::Cop::VisibilityHelp

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Macros
Defined in: lib/rubocop/cop/mixin/visibility_help.rb

Overview

Help methods for determining node visibility.

Constant Summary

Instance Method Summary

Instance Method Details

#find_visibility_end(node) (private)

Navigate to find the last protected method

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/visibility_help.rb', line 48

def find_visibility_end(node)
  possible_visibilities = VISIBILITY_SCOPES - ::Set[node_visibility(node)]
  right = node.right_siblings
  right.find do |child_node|
    possible_visibilities.include?(node_visibility(child_node))
  end || right.last
end

#find_visibility_start(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/visibility_help.rb', line 43

def find_visibility_start(node)
  node.left_siblings.reverse.find { |sibling| visibility_block?(sibling) }
end

#node_visibility(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/visibility_help.rb', line 15

def node_visibility(node)
  node_visibility_from_visibility_inline(node) ||
    node_visibility_from_visibility_block(node) ||
    :public
end

#node_visibility_from_visibility_block(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/visibility_help.rb', line 39

def node_visibility_from_visibility_block(node)
  find_visibility_start(node)&.method_name
end

#node_visibility_from_visibility_inline(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/visibility_help.rb', line 21

def node_visibility_from_visibility_inline(node)
  return unless node.def_type?

  node_visibility_from_visibility_inline_on_def(node) ||
    node_visibility_from_visibility_inline_on_method_name(node)
end

#node_visibility_from_visibility_inline_on_def(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/visibility_help.rb', line 28

def node_visibility_from_visibility_inline_on_def(node)
  parent = node.parent
  parent.method_name if visibility_inline_on_def?(parent)
end

#node_visibility_from_visibility_inline_on_method_name(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/visibility_help.rb', line 33

def node_visibility_from_visibility_inline_on_method_name(node)
  node.right_siblings.reverse.find do |sibling|
    visibility_inline_on_method_name?(sibling, method_name: node.method_name)
  end&.method_name
end

#visibility_block?(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/visibility_help.rb', line 57

def_node_matcher :visibility_block?, <<~PATTERN
  (send nil? VISIBILITY_SCOPES)
PATTERN

#visibility_inline_on_def?(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/visibility_help.rb', line 62

def_node_matcher :visibility_inline_on_def?, <<~PATTERN
  (send nil? VISIBILITY_SCOPES def)
PATTERN

#visibility_inline_on_method_name?(node, method_name:) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/visibility_help.rb', line 67

def_node_matcher :visibility_inline_on_method_name?, <<~PATTERN
  (send nil? VISIBILITY_SCOPES (sym %method_name))
PATTERN