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

Inherits:
Processor
  • Object
show all
Defined in:
foobara-0.6.1/projects/typesystem/projects/value/src/processor/multi.rb

Direct Known Subclasses

Pipeline, Selection

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#prioritizeObject

Returns the value of attribute prioritize.



5
6
7
# File 'projects/typesystem/projects/value/src/processor/multi.rb', line 5

def prioritize
  @prioritize
end

#processorsObject

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

Returns:

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

Returns:

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



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_errorsObject



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_namesObject



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