Class: Lite::Command::FaultStreamer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, object) ⇒ FaultStreamer

Returns a new instance of FaultStreamer.



9
10
11
12
# File 'lib/lite/command/fault_streamer.rb', line 9

def initialize(command, object)
  @command = command
  @object = object
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



7
8
9
# File 'lib/lite/command/fault_streamer.rb', line 7

def command
  @command
end

#objectObject (readonly)

Returns the value of attribute object.



7
8
9
# File 'lib/lite/command/fault_streamer.rb', line 7

def object
  @object
end

Instance Method Details

#caused_byObject



28
29
30
# File 'lib/lite/command/fault_streamer.rb', line 28

def caused_by
  Utils.try(object, :caused_by) || command
end

#command_exceptionObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/lite/command/fault_streamer.rb', line 38

def command_exception
  return if command.success?

  Fault.build(
    command.status.capitalize,
    command,
    object,
    dynamic: command.send(:raise_dynamic_faults?)
  )
end

#metadataObject



24
25
26
# File 'lib/lite/command/fault_streamer.rb', line 24

def 
  Utils.try(object, :metadata) || command.
end

#reasonObject



14
15
16
17
18
19
20
21
22
# File 'lib/lite/command/fault_streamer.rb', line 14

def reason
  if object.respond_to?(:reason)
    object.reason
  elsif object.is_a?(StandardError)
    Utils.pretty_exception(object)
  else
    object
  end
end

#thrown_byObject



32
33
34
35
36
# File 'lib/lite/command/fault_streamer.rb', line 32

def thrown_by
  return object if Utils.try(object, :executed?)

  Utils.try(object, :thrown_by) || command.caused_by
end