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

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

Overview

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 =
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



8
9
10
11
12
13
14
15
16
17
18
19
# 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