Class: Herb::Errors::DotNotationCasingError

Inherits:
Error
  • Object
show all
Includes:
Colors
Defined in:
lib/herb/errors.rb,
ext/herb/error_helpers.c

Constant Summary

Constants included from Colors

Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR

Instance Attribute Summary collapse

Attributes inherited from Error

#location, #message, #type

Instance Method Summary collapse

Methods included from Colors

bold, bright_magenta, cyan, dimmed, enabled?, fg, fg_bg, green, magenta, red, white, yellow

Methods inherited from Error

#class_name, #error_name, #to_json

Constructor Details

#initialize(type, location, message, segment) ⇒ DotNotationCasingError

: (String, Location?, String, Herb::Token) -> void



1497
1498
1499
1500
# File 'lib/herb/errors.rb', line 1497

def initialize(type, location, message, segment)
  super(type, location, message)
  @segment = segment
end

Instance Attribute Details

#segmentObject (readonly)

| segment: Herb::Token?, | }



1494
1495
1496
# File 'lib/herb/errors.rb', line 1494

def segment
  @segment
end

Instance Method Details

#inspectObject

: () -> String



1503
1504
1505
# File 'lib/herb/errors.rb', line 1503

def inspect
  tree_inspect.rstrip.gsub(/\s+$/, "")
end

#to_hashObject

: () -> serialized_dot_notation_casing_error



1508
1509
1510
1511
1512
# File 'lib/herb/errors.rb', line 1508

def to_hash
  super.merge(
    segment: segment
  ) #: Herb::serialized_dot_notation_casing_error
end

#tree_inspect(indent: 0, depth: 0, depth_limit: 25) ⇒ Object

: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String



1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
# File 'lib/herb/errors.rb', line 1515

def tree_inspect(indent: 0, depth: 0, depth_limit: 25)
  output = +""

  output += white("@ #{bold(red(error_name))} #{dimmed("(location: #{location&.tree_inspect})\n")}")
  output += white("├── message: #{green(message.inspect)}\n")
  output += white("└── segment: ")
  output += segment ? segment.tree_inspect : magenta("")
  output += "\n"
  output += %(\n)

  output.gsub(/^/, "    " * indent)
end