Class: Herb::Errors::TagNamesMismatchError

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, opening_tag, closing_tag) ⇒ TagNamesMismatchError

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



244
245
246
247
248
# File 'lib/herb/errors.rb', line 244

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

Instance Attribute Details

#closing_tagObject (readonly)

: Herb::Token?



241
242
243
# File 'lib/herb/errors.rb', line 241

def closing_tag
  @closing_tag
end

#opening_tagObject (readonly)

| opening_tag: Herb::Token?, | closing_tag: Herb::Token?, | }



240
241
242
# File 'lib/herb/errors.rb', line 240

def opening_tag
  @opening_tag
end

Instance Method Details

#inspectObject

: () -> String



251
252
253
# File 'lib/herb/errors.rb', line 251

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

#to_hashObject

: () -> serialized_tag_names_mismatch_error



256
257
258
259
260
261
# File 'lib/herb/errors.rb', line 256

def to_hash
  super.merge(
    opening_tag: opening_tag,
    closing_tag: closing_tag
  ) #: Herb::serialized_tag_names_mismatch_error
end

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

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



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/herb/errors.rb', line 264

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("├── opening_tag: ")
  output += opening_tag ? opening_tag.tree_inspect : magenta("")
  output += "\n"
  output += white("└── closing_tag: ")
  output += closing_tag ? closing_tag.tree_inspect : magenta("")
  output += "\n"
  output += %(\n)

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