Class: ErrorToCommunicate::Heuristic

Inherits:
Object
  • Object
show all
Defined in:
lib/error_to_communicate/heuristic.rb,
lib/error_to_communicate/heuristic/exception.rb,
lib/error_to_communicate/heuristic/load_error.rb,
lib/error_to_communicate/heuristic/syntax_error.rb,
lib/error_to_communicate/heuristic/no_method_error.rb,
lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb

Defined Under Namespace

Classes: Exception, LoadError, NoMethodError, RSpecFailure, SyntaxError, WrongNumberOfArguments

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Heuristic

Returns a new instance of Heuristic.



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

def initialize(attributes)
  self.einfo   = attributes.fetch :einfo
  self.project = attributes.fetch :project
end

Instance Attribute Details

#einfoObject

Returns the value of attribute einfo.



7
8
9
# File 'lib/error_to_communicate/heuristic.rb', line 7

def einfo
  @einfo
end

#projectObject

Returns the value of attribute project.



7
8
9
# File 'lib/error_to_communicate/heuristic.rb', line 7

def project
  @project
end

Class Method Details

.for?(einfo) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


3
4
5
# File 'lib/error_to_communicate/heuristic.rb', line 3

def self.for?(einfo)
  raise NotImplementedError, "#{self} needs to implement .for? (subclass responsibility)"
end

Instance Method Details

#backtraceObject



18
19
20
# File 'lib/error_to_communicate/heuristic.rb', line 18

def backtrace
  einfo.backtrace
end

#classnameObject



14
15
16
# File 'lib/error_to_communicate/heuristic.rb', line 14

def classname
  einfo.classname
end

#explanationObject

Is this really a thing that should be in toplevel heuristic?



27
28
29
# File 'lib/error_to_communicate/heuristic.rb', line 27

def explanation
  message
end

#messageObject



22
23
24
# File 'lib/error_to_communicate/heuristic.rb', line 22

def message
  einfo.message
end

#semantic_backtraceObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/error_to_communicate/heuristic.rb', line 51

def semantic_backtrace
  [:backtrace,
    backtrace.map do |location|
      [:code, {
        location:  location,
        highlight: (location.pred && location.pred.label),
        context:   0..0,
        emphasis:  :path,
        mark:      false,
      }]
    end
  ]
end

#semantic_explanationObject



31
32
33
# File 'lib/error_to_communicate/heuristic.rb', line 31

def semantic_explanation
  explanation
end

#semantic_infoObject



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

def semantic_info
  [:null]
end

#semantic_summaryObject

The responsibility of structuring should move to the heuristic Then, the classname and explanation can be separated from the summary and columns. Which allows us to compose heuristics by composing their columnal information, and placing it in our own structural format



40
41
42
43
44
45
# File 'lib/error_to_communicate/heuristic.rb', line 40

def semantic_summary
  [:summary, [
    [:columns,
      [:classname,   classname],
      [:explanation, semantic_explanation]]]]
end