Class: PrismChecker::CheckDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/prism_checker/check_dispatcher.rb

Class Method Summary collapse

Class Method Details

.add(element_type, check_type, checks) ⇒ Object



163
164
165
166
# File 'lib/prism_checker/check_dispatcher.rb', line 163

def self.add(element_type, check_type, checks)
  @check_map[element_type] ||= {}
  @check_map[element_type][check_type] = checks
end

.checkers(_node, element, expectation, item_type) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/prism_checker/check_dispatcher.rb', line 138

def self.checkers(_node, element, expectation, item_type)
  expectation_type = ExpectationClassifier.classify(expectation)

  element_expectations = @check_map[item_type]

  raise_bad_element(element) unless element_expectations

  checkers = element_expectations[expectation_type]

  raise_bad_expectation(element, expectation) unless checkers

  checkers
end

.raise_bad_element(element) ⇒ Object



152
153
154
155
# File 'lib/prism_checker/check_dispatcher.rb', line 152

def self.raise_bad_element(element)
  error = "Don't know how to check #{element.class.name}"
  raise Node::BadExpectation, error
end

.raise_bad_expectation(element, expectation) ⇒ Object



157
158
159
160
161
# File 'lib/prism_checker/check_dispatcher.rb', line 157

def self.raise_bad_expectation(element, expectation)
  element_class = element.class.name || element.class.ancestors.map(&:name).compact.first || '<Unknown>'
  error = "Don't know how to compare #{element_class} with #{expectation.class.name}"
  raise Node::BadExpectation, error
end