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) “`

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.



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

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

Class Method Details

.default_rootObject



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

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

.for(exception) ⇒ Object



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

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

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



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

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

Instance Method Details

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



44
45
46
47
48
# File 'lib/console/event/failure.rb', line 44

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

#to_hashObject



36
37
38
39
40
41
42
# File 'lib/console/event/failure.rb', line 36

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