Class: Fractor::Workflow::Helpers::ValidationWorker
- Inherits:
-
Fractor::Worker
- Object
- Fractor::Worker
- Fractor::Workflow::Helpers::ValidationWorker
- Defined in:
- lib/fractor/workflow/helpers.rb
Overview
Instance Method Summary collapse
-
#add_error(message) ⇒ Object
Add a validation error.
-
#build_output(input, errors) ⇒ Object
Override to customize output format Default: returns hash with valid? flag and errors.
-
#initialize ⇒ ValidationWorker
constructor
A new instance of ValidationWorker.
- #process(work) ⇒ Object
-
#validate(input) ⇒ Object
Override in subclasses to define validation logic Use add_error(message) to record errors.
Methods inherited from Fractor::Worker
effective_timeout, input_type, output_type, timeout, #timeout
Constructor Details
#initialize ⇒ ValidationWorker
Returns a new instance of ValidationWorker.
153 154 155 156 |
# File 'lib/fractor/workflow/helpers.rb', line 153 def initialize super @errors = [] end |
Instance Method Details
#add_error(message) ⇒ Object
Add a validation error
175 176 177 |
# File 'lib/fractor/workflow/helpers.rb', line 175 def add_error() @errors << end |
#build_output(input, errors) ⇒ Object
Override to customize output format Default: returns hash with valid? flag and errors
181 182 183 184 185 186 187 |
# File 'lib/fractor/workflow/helpers.rb', line 181 def build_output(input, errors) { valid: errors.empty?, errors: errors, input: input, } end |
#process(work) ⇒ Object
158 159 160 161 162 163 164 165 166 |
# File 'lib/fractor/workflow/helpers.rb', line 158 def process(work) input = work.input @errors = [] validate(input) output = build_output(input, @errors) Fractor::WorkResult.new(result: output, work: work) end |
#validate(input) ⇒ Object
Override in subclasses to define validation logic Use add_error(message) to record errors
170 171 172 |
# File 'lib/fractor/workflow/helpers.rb', line 170 def validate(input) raise NotImplementedError, "Subclasses must implement #validate" end |