Exception: Puffy::PuffyError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/puffy.rb

Overview

Base class for application errors with a configuration file

Direct Known Subclasses

ParseError, SyntaxError

Instance Method Summary collapse

Constructor Details

#initialize(message, token) ⇒ PuffyError

Returns a new instance of PuffyError.



20
21
22
23
# File 'lib/puffy.rb', line 20

def initialize(message, token)
  super(message)
  @token = token
end

Instance Method Details

#extraObject



45
46
47
# File 'lib/puffy.rb', line 45

def extra
  '~' * (length - 1)
end

#filenameObject



25
26
27
# File 'lib/puffy.rb', line 25

def filename
  @token[:filename]
end

#lengthObject



41
42
43
# File 'lib/puffy.rb', line 41

def length
  @token.fetch(:length, 1)
end

#lineObject



33
34
35
# File 'lib/puffy.rb', line 33

def line
  @token[:line]
end

#linenoObject



29
30
31
# File 'lib/puffy.rb', line 29

def lineno
  @token[:lineno]
end

#positionObject



37
38
39
# File 'lib/puffy.rb', line 37

def position
  @token[:position]
end

#to_sObject



49
50
51
52
53
54
55
# File 'lib/puffy.rb', line 49

def to_s
  <<~MESSAGE
    #{filename}:#{lineno}:#{position + 1}: #{super}
    #{line}
    #{' ' * position}^#{extra}
  MESSAGE
end