Class: Foobara::Value::Processor::Multi
- Inherits:
-
Processor
- Object
- Processor
- Foobara::Value::Processor::Multi
- Defined in:
- foobara-0.6.1/projects/typesystem/projects/value/src/processor/multi.rb
Instance Attribute Summary collapse
-
#prioritize ⇒ Object
Returns the value of attribute prioritize.
-
#processors ⇒ Object
Returns the value of attribute processors.
Class Method Summary collapse
Instance Method Summary collapse
- #applicable?(value) ⇒ Boolean
- #error_classes ⇒ Object
-
#initialize(processors: [], prioritize: true) ⇒ Multi
constructor
A new instance of Multi.
- #possible_errors ⇒ Object
- #processor_names ⇒ Object
- #register(processor) ⇒ Object
Constructor Details
#initialize(processors: [], prioritize: true) ⇒ Multi
Returns a new instance of Multi.
13 14 15 16 17 |
# File 'projects/typesystem/projects/value/src/processor/multi.rb', line 13 def initialize(*, processors: [], prioritize: true) self.prioritize = prioritize self.processors = prioritize ? processors.sort_by(&:priority) : processors super(*) end |
Instance Attribute Details
#prioritize ⇒ Object
Returns the value of attribute prioritize.
5 6 7 |
# File 'projects/typesystem/projects/value/src/processor/multi.rb', line 5 def prioritize @prioritize end |
#processors ⇒ Object
Returns the value of attribute processors.
5 6 7 |
# File 'projects/typesystem/projects/value/src/processor/multi.rb', line 5 def processors @processors end |
Class Method Details
.requires_declaration_data? ⇒ Boolean
8 9 10 |
# File 'projects/typesystem/projects/value/src/processor/multi.rb', line 8 def requires_declaration_data? false end |
Instance Method Details
#applicable?(value) ⇒ Boolean
27 28 29 |
# File 'projects/typesystem/projects/value/src/processor/multi.rb', line 27 def applicable?(value) super || processors.any? { |processor| processor.applicable?(value) } end |
#error_classes ⇒ Object
23 24 25 |
# File 'projects/typesystem/projects/value/src/processor/multi.rb', line 23 def error_classes normalize_error_classes([*super, *processors.map(&:error_classes).flatten]) end |
#possible_errors ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'projects/typesystem/projects/value/src/processor/multi.rb', line 31 def possible_errors return @possible_errors if @possible_errors h = super.to_h do |possible_error| [possible_error.key.to_s, possible_error] end processors.map(&:possible_errors).flatten.each do |possible_error| h[possible_error.key.to_s] = possible_error end # TODO: change this back to a hash @possible_errors = h.values end |
#processor_names ⇒ Object
19 20 21 |
# File 'projects/typesystem/projects/value/src/processor/multi.rb', line 19 def processor_names processors.map(&:name) end |
#register(processor) ⇒ Object
46 47 48 |
# File 'projects/typesystem/projects/value/src/processor/multi.rb', line 46 def register(processor) self.processors = [*processors, processor].sort_by(&:priority) end |