Exception: JSONP3::Path::Error
- Defined in:
- lib/json_p3/errors.rb
Overview
Base class for all JSONPath errors.
Direct Known Subclasses
Constant Summary collapse
- FULL_MESSAGE =
((RUBY_VERSION.split(".")&.map(&:to_i) <=> [3, 2, 0]) || -1) < 1
Instance Method Summary collapse
- #detailed_message(highlight: true, **_kwargs) ⇒ Object
- #full_message(highlight: true, order: :top) ⇒ Object
-
#initialize(msg, token, query) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(msg, token, query) ⇒ Error
Returns a new instance of Error.
12 13 14 15 16 |
# File 'lib/json_p3/errors.rb', line 12 def initialize(msg, token, query) super(msg) @token = token @query = query end |
Instance Method Details
#detailed_message(highlight: true, **_kwargs) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/json_p3/errors.rb', line 18 def (highlight: true, **_kwargs) if @query.strip.empty? "empty query" else value = JSONP3::Path.get_token_value(@token, @query) lines = @query[...@token[1]]&.lines or [""] # pleasing the type checker lineno = lines.length col = lines.last.length pad = " " * lineno.to_s.length pointer = (" " * col) + ("^" * [value.length, 1].max) <<~ENDOFMESSAGE.strip #{self.class}: #{} #{pad} -> '#{@query}' #{lineno}:#{col} #{pad} | #{lineno} | #{@query} #{pad} | #{pointer} #{highlight ? "\e[1m#{}\e[0m" : } ENDOFMESSAGE end end |
#full_message(highlight: true, order: :top) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/json_p3/errors.rb', line 38 def (highlight: true, order: :top) if FULL_MESSAGE # For Ruby < 3.2.0 "#{super}\n#{(highlight: highlight, order: order)}" else super end end |