Exception: Jsapi::DSL::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/jsapi/dsl/error.rb

Overview

Raised when an error occurred while defining an API component.

Instance Method Summary collapse

Constructor Details

#initialize(error_or_message, origin = nil) ⇒ Error

Creates a new error. origin is the innermost position at where the error occurred.



10
11
12
13
14
15
16
17
18
19
# File 'lib/jsapi/dsl/error.rb', line 10

def initialize(error_or_message, origin = nil)
  @path = Array(origin)
  super(
    if error_or_message.respond_to?(:message)
      error_or_message.message
    else
      error_or_message
    end
  )
end

Instance Method Details

#messageObject

Overrides StandardError#message to append the whole path of the position at where the error occurred, for example: {message} (at foo / bar).



24
25
26
27
28
29
# File 'lib/jsapi/dsl/error.rb', line 24

def message
  message = super
  return message if @path.empty?

  "#{message} (at #{@path.join(' / ')})"
end

#prepend_origin(origin) ⇒ Object

Prepends origin to the path at where the error occurred.



32
33
34
35
# File 'lib/jsapi/dsl/error.rb', line 32

def prepend_origin(origin)
  @path.prepend(origin) if origin.present?
  self
end