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.



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

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).



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

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.



30
31
32
33
# File 'lib/jsapi/dsl/error.rb', line 30

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