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.

Helps to calculate code length for the provided node.

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)

15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb', line 15

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.


29
30
31
32
# File 'lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb', line 29

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.


11
12
13
# File 'lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb', line 11

def reset_repeated_csend
  @repeated_csend = {}
end