Module: Foobara::Types::Type::Concerns::SupportedProcessorRegistration
- Included in:
- Foobara::Types::Type
- Defined in:
- foobara-0.5.8/projects/typesystem/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_classes ⇒ Object
20
21
22
23
24
25
26
|
# File 'projects/typesystem/projects/types/src/type/concerns/supported_processor_registration.rb', line 20
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
28
29
30
31
32
33
34
35
36
37
|
# File 'projects/typesystem/projects/types/src/type/concerns/supported_processor_registration.rb', line 28
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
raise MissingProcessorError, "No such processor for #{processor_symbol}"
end
end
|
#register_supported_processor_class(processor_class, symbol: processor_class.symbol) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'projects/typesystem/projects/types/src/type/concerns/supported_processor_registration.rb', line 39
def register_supported_processor_class(processor_class, symbol: processor_class.symbol)
unless symbol.is_a?(Symbol)
raise "Invalid symbol value #{symbol.inspect}. Should instead be a symbol but was a #{symbol.class.name}"
end
if supported_processor_classes.key?(symbol)
raise "There's already a processor registered for #{symbol}"
end
supported_processor_classes[symbol] = processor_class
end
|
#supported_processor_classes ⇒ Object
16
17
18
|
# File 'projects/typesystem/projects/types/src/type/concerns/supported_processor_registration.rb', line 16
def supported_processor_classes
@supported_processor_classes ||= {}
end
|