Class: Julewire::Core::Processing::ProcessorChain

Inherits:
Object
  • Object
show all
Defined in:
lib/julewire/core/processing/processor_chain.rb

Defined Under Namespace

Classes: ErrorResult

Constant Summary collapse

DROP =
Core.sentinel(:drop)

Instance Method Summary collapse

Constructor Details

#initialize(processors:, error_backtrace_lines:, on_error:) ⇒ ProcessorChain

Returns a new instance of ProcessorChain.



10
11
12
13
14
# File 'lib/julewire/core/processing/processor_chain.rb', line 10

def initialize(processors:, error_backtrace_lines:, on_error:)
  @processors = processors
  @error_backtrace_lines = error_backtrace_lines
  @on_error = on_error
end

Instance Method Details

#call(draft) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/julewire/core/processing/processor_chain.rb', line 18

def call(draft)
  current = draft

  @processors.each do |processor|
    current = apply_processor_result(current, processor.call(current))
    break if current == :drop
  rescue StandardError => e
    action = handle_processor_error(processor, e, current)
    case action
    when :continue
      next
    when :drop
      return DROP
    else
      return action
    end
  end

  current == :drop ? DROP : current
end

#empty?Boolean

Returns:

  • (Boolean)


16
# File 'lib/julewire/core/processing/processor_chain.rb', line 16

def empty? = @processors.empty?