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)


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

def initialize(cause:)
  @cause = cause
end

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



13
14
15
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_cause.rb', line 13

def cause
  @cause
end

#exceptionStandardError? (readonly)

Returns:

  • (StandardError, nil)


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

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)


36
37
38
39
40
41
42
43
44
45
46
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_cause.rb', line 36

def call
  return "" unless cause

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