Sha256: 7e3ac9e80d9213bb4d0f1a602d5cd66ad79ffee20218118811b128b49bb5b5f4

Contents?: true

Size: 1006 Bytes

Versions: 4

Compression:

Stored size: 1006 Bytes

Contents

# frozen_string_literal: true

module Lite
  module Command
    class FaultStreamer

      attr_reader :command, :object

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

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

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

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

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

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

      def command_exception
        return if command.success?

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

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lite-command-3.2.1 lib/lite/command/fault_streamer.rb
lite-command-3.2.0 lib/lite/command/fault_streamer.rb
lite-command-3.1.5 lib/lite/command/fault_streamer.rb
lite-command-3.1.4 lib/lite/command/fault_streamer.rb