From c09e2c647fd189922106216993fcd86fe6976b58 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Sat, 18 Jul 2020 17:51:13 -0400 Subject: [PATCH] Refactor Commissionner --- lib/rubocop/cop/commissioner.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/rubocop/cop/commissioner.rb b/lib/rubocop/cop/commissioner.rb index 3050122efa6..e154292aa30 100644 --- a/lib/rubocop/cop/commissioner.rb +++ b/lib/rubocop/cop/commissioner.rb @@ -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 @@ -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) @@ -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