Class: Console::Output::Failure

Inherits:
Wrapper
  • Object
show all
Defined in:
lib/console/output/failure.rb

Overview

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

Instance Attribute Summary

Attributes inherited from Wrapper

#delegate

Instance Method Summary collapse

Methods inherited from Wrapper

#last_output, #verbose!

Constructor Details

#initialize(output, **options) ⇒ Failure

Returns a new instance of Failure.



13
14
15
# File 'lib/console/output/failure.rb', line 13

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

Instance Method Details

#call(subject = nil, *arguments, exception: nil, **options, &block) ⇒ Object

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/console/output/failure.rb', line 18

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)
end