Class: Brut::TUI::Events::Exception

Inherits:
BaseEvent
  • Object
show all
Defined in:
lib/brut/tui/events/exception.rb

Overview

Fired when an exception is caught. In general, your code should endeavor to catch exceptions, wrap them in this, and fir it.

You can control if the app should exit by setting fatal: true when creating the event. Note that by default, all exceptions are treated as fatal, since you generally don't want to use them for control flow.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseEvent

handler_method_name

Constructor Details

#initialize(exception) ⇒ Exception

Returns a new instance of Exception.



9
10
11
# File 'lib/brut/tui/events/exception.rb', line 9

def initialize(exception)
  @exception = exception
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



8
9
10
# File 'lib/brut/tui/events/exception.rb', line 8

def exception
  @exception
end

Instance Method Details

#deconstruct_keys(keys = nil) ⇒ Object

Includes exception, which is the exception that triggered this event.



21
22
23
# File 'lib/brut/tui/events/exception.rb', line 21

def deconstruct_keys(keys=nil)
  super.merge({ exception: @exception})
end

#drain_then_exit?Boolean

Returns true if this event is not considered fatal.

Returns:

  • (Boolean)


14
# File 'lib/brut/tui/events/exception.rb', line 14

def drain_then_exit? = !exit?

#exit?Boolean

By default, all exceptions should cause an immediate exit. You may subclass this event to do something different, noting that #drain_then_exit? returns true if this returns false.

Returns:

  • (Boolean)


18
# File 'lib/brut/tui/events/exception.rb', line 18

def exit?            =  true