Class: ConvenientService::Service::Plugins::RescuesResultUnhandledExceptions::Commands::FormatCause

Inherits:
ConvenientService::Support::Command show all
Defined in:
lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_cause.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ConvenientService::Support::Command

[], call

Constructor Details

#initialize(cause:) ⇒ void

Parameters:

  • cause (StandardError)


24
25
26
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_cause.rb', line 24

def initialize(cause:)
  @cause = cause
end

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



18
19
20
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_cause.rb', line 18

def cause
  @cause
end

#exceptionStandardError? (readonly)

Returns:

  • (StandardError, nil)


18
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_cause.rb', line 18

attr_reader :cause

Instance Method Details

#callString

Note:

Cause formatting is inspired by RSpec. It has almost the same output (at least for RSpec 3).

Examples:

Cause.


------------------
--- Caused by: ---
StandardError:
  cause message
# /gem/lib/convenient_service/factories/service/class.rb:41:in `result'

Returns:

  • (String)


41
42
43
44
45
46
47
48
49
50
51
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_cause.rb', line 41

def call
  return "" unless cause

  <<~MESSAGE.chomp
    ------------------
    --- Caused by: ---
    #{formatted_cause_class}
    #{formatted_cause_message}
    #{formatted_cause_first_line}
  MESSAGE
end