Cuprum

An opinionated implementation of the Command pattern for Ruby applications. Cuprum wraps your business logic in a consistent, object-oriented interface and features status and error management, composability and control flow management.

Handling Exceptions

Cuprum defines a utility module to rescue uncaught exceptions when calling a command.

class UnsafeCommand < Cuprum::Command
  private

  def process
    raise 'Something went wrong.'
  end
end

class SafeCommand < UnsafeCommand
  include Cuprum::ExceptionHandling
end

UnsafeCommand.new.call
#=> raises a StandardError

result = SafeCommand.new.call
#=> a Cuprum::Result
result.error
#=> a Cuprum::Errors::UncaughtException error.
result.error.message
#=> 'uncaught exception in SafeCommand -' \
#   ' StandardError: Something went wrong.'

Exception handling is not included by default - add include Cuprum::ExceptionHandling to your command classes to use this feature.


Back to Documentation | Versions | 1.0 | Commands