123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::ConfigObsoletion::ExtractedCop Private

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, CopRule, Rule
Instance Chain:
self, CopRule, Rule
Inherits: RuboCop::ConfigObsoletion::CopRule
Defined in: lib/rubocop/config_obsoletion/extracted_cop.rb

Overview

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

Class Method Summary

CopRule - Inherited

Rule - Inherited

Instance Attribute Summary

CopRule - Inherited

#cop_rule?, #old_name, #violated?,
#warning?

Cop rules currently can only be failures, not warnings.

Rule - Inherited

#cop_rule?

Does this rule relate to cops?

#parameter_rule?

Does this rule relate to parameters?

#violated?, #config

Instance Method Summary

CopRule - Inherited

Rule - Inherited

Instance Attribute Details

#department (readonly)

[ GitHub ]

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

attr_reader :gem, :department

#feature_loaded?Boolean (readonly, private)

[ GitHub ]

  
# File 'lib/rubocop/config_obsoletion/extracted_cop.rb', line 41

def feature_loaded?
  config.loaded_features.include?(gem)
end

#gem (readonly)

[ GitHub ]

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

attr_reader :gem, :department

#violated?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubocop/config_obsoletion/extracted_cop.rb', line 17

def violated?
  return false if feature_loaded?

  affected_cops.any?
end

Instance Method Details

#affected_cops (private)

[ GitHub ]

  
# File 'lib/rubocop/config_obsoletion/extracted_cop.rb', line 32

def affected_cops
  return old_name unless old_name.end_with?('*')

  # Handle whole departments (expressed as `Department/*`)
  config.keys.select do |key|
    key == department || key.start_with?("#{department}/")
  end
end

#rule_message

[ GitHub ]

  
# 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