From 9268da82362842b2c7cf9a013bfafd1ae5d2ecad Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 21:43:44 +0200 Subject: [PATCH] Refactor Procedure#switch_list_order --- app/models/procedure.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 6e31a70ad..0c33a5e94 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -82,12 +82,17 @@ class Procedure < ActiveRecord::Base end def switch_list_order(list, index_of_first_element) - return false if index_of_first_element < 0 - return false if index_of_first_element == list.count - 1 - return false if list.count < 1 - list[index_of_first_element].update_attributes(order_place: index_of_first_element + 1) - list[index_of_first_element + 1].update_attributes(order_place: index_of_first_element) - true + if index_of_first_element < 0 || + index_of_first_element == list.count - 1 || + list.count < 1 + + false + else + list[index_of_first_element].update_attributes(order_place: index_of_first_element + 1) + list[index_of_first_element + 1].update_attributes(order_place: index_of_first_element) + + true + end end def locked?