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
-
VISIBILITY_SCOPES =
# File 'lib/rubocop/cop/mixin/visibility_help.rb', line 11::Set[:private, :protected, :public].freeze
Instance Method Summary
-
#find_visibility_end(node)
private
Navigate to find the last protected method.
- #find_visibility_start(node) private
- #node_visibility(node) private
- #node_visibility_from_visibility_block(node) private
- #node_visibility_from_visibility_inline(node) private
- #node_visibility_from_visibility_inline_on_def(node) private
- #node_visibility_from_visibility_inline_on_method_name(node) private
- #visibility_block?(node) private
- #visibility_inline_on_def?(node) private
- #visibility_inline_on_method_name?(node, method_name:) private
Instance Method Details
#find_visibility_end(node) (private)
Navigate to find the last protected method
# 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