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?