Class: RuboCop::ConfigObsoletion::ExtractedCop Private

Inherits:
CopRule
  • Object
show all
Defined in:
lib/rubocop/config_obsoletion/extracted_cop.rb

Overview

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

Encapsulation of a ConfigObsoletion rule for splitting a cop’s functionality into multiple new cops.

Instance Attribute Summary collapse

Attributes inherited from CopRule

#old_name

Instance Method Summary collapse

Methods inherited from CopRule

#cop_rule?, #message, #warning?

Methods inherited from Rule

#cop_rule?, #parameter_rule?

Constructor Details

#initialize(config, old_name, gem) ⇒ ExtractedCop

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 a new instance of ExtractedCop.



11
12
13
14
15
# File 'lib/rubocop/config_obsoletion/extracted_cop.rb', line 11

def initialize(config, old_name, gem)
  super(config, old_name)
  @department, * = old_name.rpartition('/')
  @gem = gem
end

Instance Attribute Details

#departmentObject (readonly)

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.



9
10
11
# File 'lib/rubocop/config_obsoletion/extracted_cop.rb', line 9

def department
  @department
end

#gemObject (readonly)

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.



9
10
11
# File 'lib/rubocop/config_obsoletion/extracted_cop.rb', line 9

def gem
  @gem
end

Instance Method Details

#rule_messageObject

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.



23
24
25
26
27
28
# File 'lib/rubocop/config_obsoletion/extracted_cop.rb', line 23

def rule_message
  msg = '%<name>s been extracted to the `%<gem>s` gem.'
  format(msg,
         name: affected_cops.size > 1 ? "`#{department}` cops have" : "`#{old_name}` has",
         gem: gem)
end

#violated?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)


17
18
19
20
21
# File 'lib/rubocop/config_obsoletion/extracted_cop.rb', line 17

def violated?
  return false if feature_loaded?

  affected_cops.any?
end