From ee5f34e781ab8005dd2c9e92541831402a9b4f13 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Mon, 11 Aug 2014 13:50:48 +0000 Subject: [PATCH] Reduce duplication in and between trace/null reporters --- config/flay.yml | 2 +- lib/mutant/reporter/null.rb | 50 +++----------------------------- lib/mutant/reporter/trace.rb | 55 ++++-------------------------------- 3 files changed, 10 insertions(+), 97 deletions(-) diff --git a/config/flay.yml b/config/flay.yml index 3a181d8d..48ccab31 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 18 -total_score: 1066 +total_score: 1071 diff --git a/lib/mutant/reporter/null.rb b/lib/mutant/reporter/null.rb index b4373e1c..d2e108a8 100644 --- a/lib/mutant/reporter/null.rb +++ b/lib/mutant/reporter/null.rb @@ -5,52 +5,10 @@ module Mutant class Null < self include Equalizer.new - # Write warning message - # - # @param [String] _message - # - # @return [self] - # - # @api private - # - def warn(_message) - self - end - - # Report object - # - # @param [Object] _object - # - # @return [self] - # - # @api private - # - def report(_object) - self - end - - # Report start - # - # @param [Object] _object - # - # @return [self] - # - # @api private - # - def start(_object) - self - end - - # Report progress on object - # - # @param [Object] _object - # - # @return [self] - # - # @api private - # - def progress(_object) - self + %w[warn report start progress].each do |name| + define_method name do |_object| + self + end end end # Null diff --git a/lib/mutant/reporter/trace.rb b/lib/mutant/reporter/trace.rb index 829edceb..6f6b1916 100644 --- a/lib/mutant/reporter/trace.rb +++ b/lib/mutant/reporter/trace.rb @@ -14,56 +14,11 @@ module Mutant super(Hash[anima.attribute_names.map { |name| [name, []] }]) end - # Warn with message - # - # @param [String] message - # - # @return [self] - # - # @api private - # - def warn(message) - warn_calls << message - self - end - - # Report object - # - # @param [Object] object - # - # @return [self] - # - # @api private - # - def report(object) - report_calls << object - self - end - - # Report new progress on object - # - # @param [Object] object - # - # @return [self] - # - # @api private - # - def start(object) - start_calls << object - self - end - - # Report new progress on object - # - # @param [Object] object - # - # @return [self] - # - # @api private - # - def progress(object) - progress_calls << object - self + %w[start progress report warn].each do |name| + define_method(name) do |object| + public_send(:"#{name}_calls") << object + self + end end end # Tracker