Exception: Jsapi::DSL::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Jsapi::DSL::Error
- Defined in:
- lib/jsapi/dsl/error.rb
Overview
Raised when an error occurred while defining an API component.
Instance Method Summary collapse
-
#initialize(error_or_message, origin = nil) ⇒ Error
constructor
Creates a new error.
-
#message ⇒ Object
Overrides
StandardError#messageto append the whole path of the position at where the error occurred, for example:{message} (at foo / bar). -
#prepend_origin(origin) ⇒ Object
Prepends
originto the path at where the error occurred.
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(, origin = nil) @path = Array(origin) super( if .respond_to?(:message) . else end ) end |
Instance Method Details
#message ⇒ Object
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 = super return 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 |