Class: Foobara::Value::Processor::Multi

Inherits:
Foobara::Value::Processor show all
Defined in:
foobara-0.0.110/projects/value/src/processor/multi.rb

Direct Known Subclasses

Pipeline, Selection

Instance Attribute Summary collapse

Attributes inherited from Foobara::Value::Processor

#created_in_namespace, #declaration_data, #parent_declaration_data

Class Method Summary collapse

Instance Method Summary collapse

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

#prioritizeObject

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

#processorsObject

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

Returns:

  • (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

Returns:

  • (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_classesObject



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_errorsObject



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_namesObject



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