From f46c23787ecfbf8e0e89e8e8d587c79a0ff04a58 Mon Sep 17 00:00:00 2001 From: Dmitry Babenko Date: Fri, 6 Mar 2020 19:08:27 +0200 Subject: [PATCH] Move #on method from Command to Performable --- lib/auxiliary_rails/application/command.rb | 10 ---------- lib/auxiliary_rails/concerns/performable.rb | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/auxiliary_rails/application/command.rb b/lib/auxiliary_rails/application/command.rb index b88a657..ac274fa 100644 --- a/lib/auxiliary_rails/application/command.rb +++ b/lib/auxiliary_rails/application/command.rb @@ -43,16 +43,6 @@ def i18n_scope end end - def on(status, &_block) - ensure_execution! - - return self unless status?(status) - - yield(self) if block_given? - - self - end - protected # Shortcut reader for attributes defined by Dry::Initializer diff --git a/lib/auxiliary_rails/concerns/performable.rb b/lib/auxiliary_rails/concerns/performable.rb index 6bc0d0f..0d77ef2 100644 --- a/lib/auxiliary_rails/concerns/performable.rb +++ b/lib/auxiliary_rails/concerns/performable.rb @@ -53,6 +53,22 @@ def success? status?(:success) end + # Provides ability to execude block of the code depending on + # command execution status + # + # @param status [Symol] Desired command status + # @param &_block Code to be executed if status matches + # @return [self] + def on(status, &_block) + ensure_execution! + + return self unless status?(status) + + yield(self) if block_given? + + self + end + # Shortcut for ActiveRecord::Base.transaction def transaction(&block) ActiveRecord::Base.transaction(&block) if block_given?