Class: RuboCop::Cop::Betterment::Utils::HardcodedAttribute
- Inherits:
-
Object
- Object
- RuboCop::Cop::Betterment::Utils::HardcodedAttribute
- Extended by:
- NodePattern::Macros
- Defined in:
- lib/rubocop/cop/betterment/utils/hardcoded_attribute.rb
Instance Attribute Summary collapse
-
#let_name ⇒ Object
readonly
Returns the value of attribute let_name.
-
#let_node ⇒ Object
readonly
Returns the value of attribute let_node.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #correctable? ⇒ Boolean
- #each_integer_reference ⇒ Object
- #each_range_within_string(reference) ⇒ Object
- #each_string_reference ⇒ Object
-
#initialize(node) ⇒ HardcodedAttribute
constructor
A new instance of HardcodedAttribute.
- #replacement ⇒ Object
Constructor Details
#initialize(node) ⇒ HardcodedAttribute
Returns a new instance of HardcodedAttribute.
12 13 14 15 16 |
# File 'lib/rubocop/cop/betterment/utils/hardcoded_attribute.rb', line 12 def initialize(node) @node = node @let_node = node.parent&.parent&.parent @let_name = extract_let_name(@let_node) end |
Instance Attribute Details
#let_name ⇒ Object (readonly)
Returns the value of attribute let_name.
10 11 12 |
# File 'lib/rubocop/cop/betterment/utils/hardcoded_attribute.rb', line 10 def let_name @let_name end |
#let_node ⇒ Object (readonly)
Returns the value of attribute let_node.
10 11 12 |
# File 'lib/rubocop/cop/betterment/utils/hardcoded_attribute.rb', line 10 def let_node @let_node end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
10 11 12 |
# File 'lib/rubocop/cop/betterment/utils/hardcoded_attribute.rb', line 10 def node @node end |
Instance Method Details
#correctable? ⇒ Boolean
18 19 20 |
# File 'lib/rubocop/cop/betterment/utils/hardcoded_attribute.rb', line 18 def correctable? key == :id && !let_name.nil? end |
#each_integer_reference ⇒ Object
26 27 28 29 30 |
# File 'lib/rubocop/cop/betterment/utils/hardcoded_attribute.rb', line 26 def each_integer_reference each_possible_reference(:int) do |ref| yield ref if ref.value == value end end |
#each_range_within_string(reference) ⇒ Object
38 39 40 41 42 |
# File 'lib/rubocop/cop/betterment/utils/hardcoded_attribute.rb', line 38 def each_range_within_string(reference) reference.source.enum_for(:scan, value_pattern).each do yield create_range(reference, Regexp.last_match) end end |
#each_string_reference ⇒ Object
32 33 34 35 36 |
# File 'lib/rubocop/cop/betterment/utils/hardcoded_attribute.rb', line 32 def each_string_reference each_possible_reference(:str) do |ref| yield ref if ref.value.match?(value_pattern) end end |
#replacement ⇒ Object
22 23 24 |
# File 'lib/rubocop/cop/betterment/utils/hardcoded_attribute.rb', line 22 def replacement "#{let_name}.#{key}" end |