Class: Julewire::Core::Processing::ProcessorChain
- Inherits:
-
Object
- Object
- Julewire::Core::Processing::ProcessorChain
- Defined in:
- lib/julewire/core/processing/processor_chain.rb
Defined Under Namespace
Classes: ErrorResult
Constant Summary collapse
Instance Method Summary collapse
- #call(draft) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(processors:, on_error:, on_invalid:, on_invalid_draft:) ⇒ ProcessorChain
constructor
A new instance of ProcessorChain.
Constructor Details
#initialize(processors:, on_error:, on_invalid:, on_invalid_draft:) ⇒ ProcessorChain
Returns a new instance of ProcessorChain.
10 11 12 13 14 15 |
# File 'lib/julewire/core/processing/processor_chain.rb', line 10 def initialize(processors:, on_error:, on_invalid:, on_invalid_draft:) @processors = processors @on_error = on_error @on_invalid = on_invalid @on_invalid_draft = on_invalid_draft end |
Instance Method Details
#call(draft) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/julewire/core/processing/processor_chain.rb', line 19 def call(draft) current = draft @processors.each do |processor| result = processor.call(current) current = apply_processor_result(current, processor, result) return DROP if current.equal?(DROP) return DROP unless valid_processor_draft?(processor, current) rescue StandardError => e action = handle_processor_error(processor, e, current) case action when :continue return DROP unless valid_processor_draft?(processor, current) when :drop return DROP else return action end end current end |
#empty? ⇒ Boolean
17 |
# File 'lib/julewire/core/processing/processor_chain.rb', line 17 def empty? = @processors.empty? |