Module: RuboCop::Cop::VariableForce::Branch Private

Defined in:
lib/rubocop/cop/variable_force/branch.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Namespace for branch classes for each control structure.

Defined Under Namespace

Modules: ExceptionHandler, LogicalOperator, SimpleConditional Classes: And, Base, Case, Ensure, For, If, Or, Rescue, Until, UntilPost, While, WhilePost

Constant Summary collapse

CLASSES_BY_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Base.classes.each_with_object({}) do |klass, classes|
  classes[klass.type] = klass
end

Class Method Summary collapse

Class Method Details

.of(target_node, scope: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rubocop/cop/variable_force/branch.rb', line 8

def self.of(target_node, scope: nil)
  ([target_node] + target_node.ancestors).each do |node|
    return nil unless node.parent
    return nil unless scope.include?(node)

    klass = CLASSES_BY_TYPE[node.parent.type]
    next unless klass

    branch = klass.new(node, scope)
    return branch if branch.branched?
  end

  nil
end