Exception: Kapusta::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/kapusta/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reason, path: nil, line: nil, column: nil) ⇒ Error

Returns a new instance of Error.



7
8
9
10
11
12
13
# File 'lib/kapusta/error.rb', line 7

def initialize(reason, path: nil, line: nil, column: nil)
  @reason = reason
  @path = path
  @line = line
  @column = column
  super(formatted)
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



5
6
7
# File 'lib/kapusta/error.rb', line 5

def column
  @column
end

#lineObject (readonly)

Returns the value of attribute line.



5
6
7
# File 'lib/kapusta/error.rb', line 5

def line
  @line
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/kapusta/error.rb', line 5

def path
  @path
end

#reasonObject (readonly)

Returns the value of attribute reason.



5
6
7
# File 'lib/kapusta/error.rb', line 5

def reason
  @reason
end

Instance Method Details

#formattedObject



15
16
17
18
# File 'lib/kapusta/error.rb', line 15

def formatted
  prefix = [path, line, column].compact.join(':')
  prefix.empty? ? reason : "#{prefix}: #{reason}"
end

#with_defaults(path: nil, line: nil, column: nil) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/kapusta/error.rb', line 20

def with_defaults(path: nil, line: nil, column: nil)
  copy = self.class.new(@reason,
                        path: @path || path,
                        line: @line || line,
                        column: @column || column)
  copy.set_backtrace(backtrace) if backtrace
  copy
end