Class: Foobara::Value::Processor::Multi
- Inherits:
-
Foobara::Value::Processor
- Object
- Foobara::Value::Processor
- Foobara::Value::Processor::Multi
- Defined in:
- foobara-0.0.110/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.
Attributes inherited from Foobara::Value::Processor
#created_in_namespace, #declaration_data, #parent_declaration_data
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
Methods inherited from Foobara::Value::Processor
#always_applicable?, #attribute_name, #build_error, default_declaration_data, #dup_processor, error_class, error_classes, #error_context, #error_message, #error_path, foobara_manifest, #foobara_manifest, #inspect, instance, #method_missing, #name, new_with_agnostic_args, #priority, #process_outcome, #process_outcome!, #process_value, #process_value!, processor_name, requires_parent_declaration_data?, #respond_to_missing?, #runner, symbol
Methods included from IsManifestable
#foobara_domain, #foobara_manifest, #foobara_organization, #scoped_clear_caches
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Constructor Details
#initialize(processors: [], prioritize: true) ⇒ Multi
Returns a new instance of Multi.
13 14 15 16 17 |
# File 'foobara-0.0.110/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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Foobara::Value::Processor
Instance Attribute Details
#prioritize ⇒ Object
Returns the value of attribute prioritize.
5 6 7 |
# File 'foobara-0.0.110/projects/value/src/processor/multi.rb', line 5 def prioritize @prioritize end |
#processors ⇒ Object
Returns the value of attribute processors.
5 6 7 |
# File 'foobara-0.0.110/projects/value/src/processor/multi.rb', line 5 def processors @processors end |
Class Method Details
.requires_declaration_data? ⇒ Boolean
8 9 10 |
# File 'foobara-0.0.110/projects/value/src/processor/multi.rb', line 8 def requires_declaration_data? false end |
Instance Method Details
#applicable?(value) ⇒ Boolean
27 28 29 |
# File 'foobara-0.0.110/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 'foobara-0.0.110/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 'foobara-0.0.110/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 'foobara-0.0.110/projects/value/src/processor/multi.rb', line 19 def processor_names processors.map(&:name) end |
#register(processor) ⇒ Object
46 47 48 |
# File 'foobara-0.0.110/projects/value/src/processor/multi.rb', line 46 def register(processor) self.processors = [*processors, processor].sort_by(&:priority) end |