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



14
15
16
# File 'lib/lite/command/fault_streamer.rb', line 14

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

#metadataObject



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

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

#reasonObject



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

def reason
  if object.respond_to?(:reason)
    object.reason
  elsif object.is_a?(StandardError)
    "[#{object.class.name}] #{object.message}".chomp(".")
  else
    object
  end
end

#thrown_byObject



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

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

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