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.
Utility module for handling uncaught exceptions in commands.
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.'#call(*args, **kwargs, &block) => Cuprum::Result
Wraps the #call method with a rescue clause matching any StandardError.
If a StandardError or subclass thereof is raised and not caught by #call, then ExceptionHandling will rescue the exception and return a failing Cuprum::Result with a Cuprum::Errors::UncaughtException error.
Back to Documentation | Versions | 1.2 | Reference | Cuprum