Skip to content

Commit

Permalink
Refactor Commissionner
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre authored and mergify[bot] committed Aug 27, 2020
1 parent b74cc72 commit c09e2c6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/rubocop/cop/commissioner.rb
Expand Up @@ -42,7 +42,7 @@ def initialize(cops, forces = [], options = {})
@cops = cops
@forces = forces
@options = options
@callbacks = {}
@callbacks = Hash.new { |h, k| h[k] = cops_callbacks_for(k) }

reset
end
Expand Down Expand Up @@ -83,9 +83,6 @@ def investigate(processed_source)
private

def trigger_responding_cops(callback, node)
@callbacks[callback] ||= @cops.select do |cop|
cop.respond_to?(callback)
end
@callbacks[callback].each do |cop|
with_cop_error_handling(cop, node) do
cop.send(callback, node)
Expand All @@ -97,6 +94,12 @@ def reset
@errors = []
end

def cops_callbacks_for(callback)
@cops.select do |cop|
cop.respond_to?(callback)
end
end

def invoke(callback, cops, *args)
cops.each do |cop|
with_cop_error_handling(cop) do
Expand Down

0 comments on commit c09e2c6

Please sign in to comment.