ConsoleSourceConsoleOutputFailure

class Failure

A wrapper for outputting failure messages, which can include exceptions.

Definitions

def initialize(output, **options)

Create a new failure output wrapper.

Implementation

def initialize(output, **options)
	super(output, **options)
end

def call(subject = nil, *arguments, exception: nil, **options, &block)

The exception must be either the last argument or passed as an option.

Signature

parameter subject String

The subject of the message.

parameter arguments Array

The arguments to output.

parameter exception Exception

The exception to output.

parameter options Hash

Additional options to pass to the output.

parameter block Proc

An optional block to pass to the output.

Implementation

def call(subject = nil, *arguments, exception: nil, **options, &block)
	if exception.nil?
		last = arguments.last
		if last.is_a?(Exception)
			options[:event] = Event::Failure.for(last)
		end
	elsif exception.is_a?(Exception)
		options[:event] = Event::Failure.for(exception)
	else
		# We don't know what this is, so we just pass it through:
		options[:exception] = exception
	end
	
	super(subject, *arguments, **options, &block)
end