Class: RuboCop::Cop::Commissioner

Inherits:
Object
  • Object
show all
Includes:
AST::Traversal
Defined in:
lib/rubocop/cop/commissioner.rb

Overview

Commissioner class is responsible for processing the AST and delegating work to the specified cops.

Defined Under Namespace

Classes: InvestigationReport

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cops, forces = [], options = {}) ⇒ Commissioner

Returns a new instance of Commissioner.



44
45
46
47
48
49
50
51
# File 'lib/rubocop/cop/commissioner.rb', line 44

def initialize(cops, forces = [], options = {})
  @cops = cops
  @forces = forces
  @options = options
  initialize_callbacks

  reset
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



42
43
44
# File 'lib/rubocop/cop/commissioner.rb', line 42

def errors
  @errors
end

Instance Method Details

#investigate(processed_source, offset: 0, original: processed_source) ⇒ InvestigationReport

Returns:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rubocop/cop/commissioner.rb', line 79

def investigate(processed_source, offset: 0, original: processed_source)
  reset

  begin_investigation(processed_source, offset: offset, original: original)
  if processed_source.valid_syntax?
    invoke(:on_new_investigation, @cops)
    invoke_with_argument(:investigate, @forces, processed_source)

    walk(processed_source.ast) unless @cops.empty?
    invoke(:on_investigation_end, @cops)
  else
    invoke(:on_other_file, @cops)
  end
  reports = @cops.map { |cop| cop.send(:complete_investigation) }
  InvestigationReport.new(processed_source, reports, @errors)
end