Module: Foobara::Types::Type::Concerns::SupportedProcessorRegistration

Included in:
Foobara::Types::Type
Defined in:
foobara-0.0.110/projects/types/src/type/concerns/supported_processor_registration.rb

Overview

What do we actually need here? we need a way to associate a type with a collection of supported processors. Type could make the most sense for this functionality. Any reason we should be decoupling the concept of validators to apply from validators that are supported and may or may not be applied? OK let’s attempt doing this on Type instead.

Defined Under Namespace

Classes: MissingProcessorError

Instance Method Summary collapse

Instance Method Details

#all_supported_processor_classesObject



18
19
20
21
22
23
24
# File 'foobara-0.0.110/projects/types/src/type/concerns/supported_processor_registration.rb', line 18

def all_supported_processor_classes
  if base_type
    supported_processor_classes.values + base_type.all_supported_processor_classes
  else
    supported_processor_classes.values
  end
end

#find_supported_processor_class(processor_symbol) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'foobara-0.0.110/projects/types/src/type/concerns/supported_processor_registration.rb', line 26

def find_supported_processor_class(processor_symbol)
  if supported_processor_classes.key?(processor_symbol)
    supported_processor_classes[processor_symbol]
  elsif base_type
    base_type.find_supported_processor_class(processor_symbol)
  else
    # TODO: can we catch this via a type declaration validator before hitting it here?
    raise MissingProcessorError, "No such processor for #{processor_symbol}"
  end
end

#register_supported_processor_class(processor_class, symbol: processor_class.symbol) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'foobara-0.0.110/projects/types/src/type/concerns/supported_processor_registration.rb', line 37

def register_supported_processor_class(processor_class, symbol: processor_class.symbol)
  unless symbol.is_a?(Symbol)
    # :nocov:
    raise "Invalid symbol value #{symbol.inspect}. Should instead be a symbol but was a #{symbol.class.name}"
    # :nocov:
  end

  if supported_processor_classes.key?(symbol)
    # :nocov:
    raise "There's already a processor registered for #{symbol}"
    # :nocov:
  end

  supported_processor_classes[symbol] = processor_class
end

#supported_processor_classesObject



14
15
16
# File 'foobara-0.0.110/projects/types/src/type/concerns/supported_processor_registration.rb', line 14

def supported_processor_classes
  @supported_processor_classes ||= {}
end