From 4624c4a8ce86390069f32be70428ec431f9a9129 Mon Sep 17 00:00:00 2001 From: Cyril Mougel Date: Fri, 6 Jul 2012 22:39:11 +0200 Subject: [PATCH] little refactoring to move all action about ProblemDestroy in ProblemDestroy class fix #208 --- app/controllers/errs_controller.rb | 6 ++---- app/interactors/problem_destroy.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/controllers/errs_controller.rb b/app/controllers/errs_controller.rb index 1797e71..84c6d22 100644 --- a/app/controllers/errs_controller.rb +++ b/app/controllers/errs_controller.rb @@ -114,10 +114,8 @@ class ErrsController < ApplicationController end def destroy_several - @selected_problems.each{|problem| - ProblemDestroy.new(problem).execute - } - flash[:notice] = "#{pluralize(@selected_problems.count, 'err has', 'errs have')} been deleted." + nb_problem_destroy = ProblemDestroy.execute(@selected_problems) + flash[:notice] = "#{pluralize(nb_problem_destroy, 'err has', 'errs have')} been deleted." redirect_to :back end diff --git a/app/interactors/problem_destroy.rb b/app/interactors/problem_destroy.rb index a863b7d..4694c74 100644 --- a/app/interactors/problem_destroy.rb +++ b/app/interactors/problem_destroy.rb @@ -12,6 +12,20 @@ class ProblemDestroy problem.delete end + ## + # Destroy all problem pass in args + # + # @params [ Array[Problem] ] problems the list of problem need to be delete + # can be a single Problem + # @return [ Integer ] + # the number of problem destroy + # + def self.execute(problems) + Array(problems).each{ |problem| + ProblemDestroy.new(problem).execute + }.count + end + private def errs_id -- libgit2 0.21.2