Class: Console::Event::Failure

Inherits:
Generic
  • Object
show all
Defined in:
lib/console/event/failure.rb

Overview

Represents a failure event.

“‘ruby Console::Event::Failure.for(exception).emit(self) “`

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#as_json, #to_json, #to_s

Constructor Details

#initialize(exception, root = Dir.getwd) ⇒ Failure

Returns a new instance of Failure.



34
35
36
37
# File 'lib/console/event/failure.rb', line 34

def initialize(exception, root = Dir.getwd)
	@exception = exception
	@root = root
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



32
33
34
# File 'lib/console/event/failure.rb', line 32

def exception
  @exception
end

Class Method Details

.default_rootObject



18
19
20
21
22
# File 'lib/console/event/failure.rb', line 18

def self.default_root
	Dir.getwd
rescue # e.g. Errno::EMFILE
	nil
end

.for(exception) ⇒ Object



24
25
26
# File 'lib/console/event/failure.rb', line 24

def self.for(exception)
	self.new(exception, self.default_root)
end

.log(subject, exception, **options) ⇒ Object



28
29
30
# File 'lib/console/event/failure.rb', line 28

def self.log(subject, exception, **options)
	Console.error(subject, **self.for(exception).to_hash, **options)
end

Instance Method Details

#emit(*arguments, **options) ⇒ Object



47
48
49
50
51
# File 'lib/console/event/failure.rb', line 47

def emit(*arguments, **options)
	options[:severity] ||= :error
	
	super
end

#to_hashObject



39
40
41
42
43
44
45
# File 'lib/console/event/failure.rb', line 39

def to_hash
	Hash.new.tap do |hash|
		hash[:type] = :failure
		hash[:root] = @root if @root
		extract(@exception, hash)
	end
end