Class: RuboCop::Cop::Commissioner
- Inherits:
-
Parser::AST::Processor
- Object
- Parser::AST::Processor
- RuboCop::Cop::Commissioner
- Defined in:
- lib/rubocop/cop/commissioner.rb
Overview
Commissioner class is responsible for processing the AST and delegating work to the specified cops.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Class Method Summary collapse
-
.call_super(callback) ⇒ Object
Methods that are not defined in Parser::AST::Processor won't have a
super
to call. - .callback_methods ⇒ Object
Instance Method Summary collapse
-
#initialize(cops, forces, options = {}) ⇒ Commissioner
constructor
A new instance of Commissioner.
- #investigate(processed_source) ⇒ Object
Constructor Details
#initialize(cops, forces, options = {}) ⇒ Commissioner
Returns a new instance of Commissioner.
25 26 27 28 29 30 |
# File 'lib/rubocop/cop/commissioner.rb', line 25 def initialize(cops, forces, = {}) @cops = cops @forces = forces @options = reset_errors end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/rubocop/cop/commissioner.rb', line 8 def errors @errors end |
Class Method Details
.call_super(callback) ⇒ Object
Methods that are not defined in Parser::AST::Processor
won't have a super
to call. So we should not attempt
to invoke super
when defining them.
17 18 19 20 21 22 23 |
# File 'lib/rubocop/cop/commissioner.rb', line 17 def self.call_super(callback) if Parser::AST::Processor.method_defined?(callback) 'super' else '' end end |
.callback_methods ⇒ Object
10 11 12 |
# File 'lib/rubocop/cop/commissioner.rb', line 10 def self.callback_methods Parser::Meta::NODE_TYPES.map { |type| "on_#{type}" } end |
Instance Method Details
#investigate(processed_source) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rubocop/cop/commissioner.rb', line 47 def investigate(processed_source) reset_errors prepare(processed_source) invoke_custom_processing(@cops, processed_source) invoke_custom_processing(@forces, processed_source) process(processed_source.ast) if processed_source.ast @cops.each_with_object([]) do |cop, offenses| filename = processed_source.buffer.name # ignore files that are of no interest to the cop in question offenses.concat(cop.offenses) if cop.relevant_file?(filename) end end |