Class: ErrorToCommunicate::ExceptionInfo::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/error_to_communicate/exception_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Location

Returns a new instance of Location.



11
12
13
14
15
16
17
18
# File 'lib/error_to_communicate/exception_info.rb', line 11

def initialize(attributes)
  self.path    = Pathname.new attributes.fetch(:path)
  self.linenum = attributes.fetch :linenum
  self.label   = attributes.fetch :label
  self.pred    = attributes.fetch :pred, nil
  self.succ    = attributes.fetch :succ, nil
  self.binding = attributes.fetch :binding
end

Instance Attribute Details

#bindingObject

Returns the value of attribute binding.



9
10
11
# File 'lib/error_to_communicate/exception_info.rb', line 9

def binding
  @binding
end

#labelObject

Returns the value of attribute label.



9
10
11
# File 'lib/error_to_communicate/exception_info.rb', line 9

def label
  @label
end

#linenumObject

Returns the value of attribute linenum.



9
10
11
# File 'lib/error_to_communicate/exception_info.rb', line 9

def linenum
  @linenum
end

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/error_to_communicate/exception_info.rb', line 9

def path
  @path
end

#predObject

Returns the value of attribute pred.



9
10
11
# File 'lib/error_to_communicate/exception_info.rb', line 9

def pred
  @pred
end

#succObject

Returns the value of attribute succ.



9
10
11
# File 'lib/error_to_communicate/exception_info.rb', line 9

def succ
  @succ
end

Class Method Details

.parse(line, binding) ⇒ Object

What if the line doesn’t match for some reason? Raise an exception? Use some reasonable default? (is there one?)



23
24
25
26
27
28
29
30
31
# File 'lib/error_to_communicate/exception_info.rb', line 23

def self.parse(line, binding)
  line =~ /^(.*?):(\d+):in `(.*?)'$/ # Are ^ and $ sufficient? Should be \A and (\Z or \z)?
  ErrorToCommunicate::ExceptionInfo::Location.new(
    path:    ($1||""),
    linenum: ($2||"-1").to_i,
    label:   ($3||line),
    binding: binding
  )
end

Instance Method Details

#==(location) ⇒ Object Also known as: eql?



39
40
41
42
43
# File 'lib/error_to_communicate/exception_info.rb', line 39

def ==(location)
  path    == location.path    &&
  linenum == location.linenum &&
  label   == location.label
end

#hashObject

is there an upper bound I need to stay within? Guessing 30 or 31 bits, but maybe it doesn’t really matter?



35
36
37
# File 'lib/error_to_communicate/exception_info.rb', line 35

def hash
  path.hash + linenum.hash + label.hash
end

#inspectObject



47
48
49
# File 'lib/error_to_communicate/exception_info.rb', line 47

def inspect
  "#<ExInfo::Loc #{path}:#{linenum}:in `#{label}' pred:#{!!pred} succ:#{!!succ}>"
end