Class: Tryouts::ExpectationEvaluators::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/tryouts/expectation_evaluators/registry.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.evaluatorsObject (readonly)

Returns the value of attribute evaluators.



25
26
27
# File 'lib/tryouts/expectation_evaluators/registry.rb', line 25

def evaluators
  @evaluators
end

Class Method Details

.evaluator_for(expectation, test_case, context) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/tryouts/expectation_evaluators/registry.rb', line 27

def evaluator_for(expectation, test_case, context)
  evaluator_class = find_evaluator_class(expectation.type)

  unless evaluator_class
    raise ArgumentError, "No evaluator found for expectation type: #{expectation.type}"
  end

  evaluator_class.new(expectation, test_case, context)
end

.register(evaluator_class) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/tryouts/expectation_evaluators/registry.rb', line 37

def register(evaluator_class)
  unless evaluator_class < Base
    raise ArgumentError, 'Evaluator must inherit from ExpectationEvaluators::Base'
  end

  @evaluators << evaluator_class unless @evaluators.include?(evaluator_class)
end

.registered_evaluatorsObject



45
46
47
# File 'lib/tryouts/expectation_evaluators/registry.rb', line 45

def registered_evaluators
  @evaluators.dup
end