Skip to content

Commit

Permalink
Move #on method from Command to Performable
Browse files Browse the repository at this point in the history
  • Loading branch information
stgeneral committed Mar 6, 2020
1 parent d42470a commit f46c237
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
10 changes: 0 additions & 10 deletions lib/auxiliary_rails/application/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tt>Dry::Initializer</tt>
Expand Down
16 changes: 16 additions & 0 deletions lib/auxiliary_rails/concerns/performable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tt>ActiveRecord::Base.transaction</tt>
def transaction(&block)
ActiveRecord::Base.transaction(&block) if block_given?
Expand Down

0 comments on commit f46c237

Please sign in to comment.