Module: RuboCop::Cop::Metrics::Utils::RepeatedCsendDiscount Private

Included in:
RuboCop::Cop::MethodComplexity, AbcSizeCalculator
Defined in:
lib/rubocop/cop/metrics/utils/repeated_csend_discount.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.

Identifies repetitions `&.` on the same variable:

my_var&.foo
my_var&.bar # => repeated
my_var = baz # => reset
my_var&.qux # => not repeated

Instance Method Summary collapse

Instance Method Details

#discount_for_repeated_csend?(csend_node) ⇒ Boolean

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.

Returns:

  • (Boolean)

20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb', line 20

def discount_for_repeated_csend?(csend_node)
  receiver = csend_node.receiver

  return false unless receiver.lvar_type?

  var_name = receiver.children.first
  seen = @repeated_csend.fetch(var_name) do
    @repeated_csend[var_name] = csend_node
    return false
  end

  !seen.equal?(csend_node)
end

#reset_on_lvasgn(node) ⇒ 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.


34
35
36
37
# File 'lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb', line 34

def reset_on_lvasgn(node)
  var_name = node.children.first
  @repeated_csend.delete(var_name)
end

#reset_repeated_csendObject

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.


16
17
18
# File 'lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb', line 16

def reset_repeated_csend
  @repeated_csend = {}
end