Exception: Lite::Command::Fault

Inherits:
StandardError
  • Object
show all
Defined in:
lib/lite/command/fault.rb

Direct Known Subclasses

Error, Failure, Invalid, Noop

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**params) ⇒ Fault

Returns a new instance of Fault.



10
11
12
13
14
15
16
17
# File 'lib/lite/command/fault.rb', line 10

def initialize(**params)
  @reason    = params.fetch(:reason)
  @metadata  = params.fetch(:metadata)
  @caused_by = params.fetch(:caused_by)
  @thrown_by = params.fetch(:thrown_by)

  super(reason)
end

Instance Attribute Details

#caused_byObject (readonly)

Returns the value of attribute caused_by.



8
9
10
# File 'lib/lite/command/fault.rb', line 8

def caused_by
  @caused_by
end

#metadataObject (readonly)

Returns the value of attribute metadata.



8
9
10
# File 'lib/lite/command/fault.rb', line 8

def 
  @metadata
end

#reasonObject (readonly)

Returns the value of attribute reason.



8
9
10
# File 'lib/lite/command/fault.rb', line 8

def reason
  @reason
end

#thrown_byObject (readonly)

Returns the value of attribute thrown_by.



8
9
10
# File 'lib/lite/command/fault.rb', line 8

def thrown_by
  @thrown_by
end

Class Method Details

.build(type, catcher, thrower, dynamic: false) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lite/command/fault.rb', line 19

def self.build(type, catcher, thrower, dynamic: false)
  klass = dynamic ? catcher.class : Lite::Command
  fault = klass.const_get(type.to_s)
  fault = fault.new(
    reason: catcher.reason,
    metadata: catcher.,
    caused_by: catcher.caused_by,
    thrown_by: catcher.thrown_by
  )
  fault.set_backtrace(thrower.backtrace) if thrower.respond_to?(:backtrace)
  fault
end

Instance Method Details

#typeObject



32
33
34
# File 'lib/lite/command/fault.rb', line 32

def type
  @type ||= self.class.name.split("::").last.downcase
end