Module: Voom::Commands::AggregateValidations
Instance Method Summary collapse
-
#aggregate_validations(*lambdas) ⇒ Object
This method will combine all parameter validation errors into a single error hash Warning: If the same key exists in two validations the last one wins You pass it a lambda that validates parameters.
- #aggregate_validations!(*lambdas) ⇒ Object
Methods included from ExtractErrors
#extract_errors, #extract_fk_errors
Instance Method Details
#aggregate_validations(*lambdas) ⇒ Object
This method will combine all parameter validation errors into a single error hash Warning: If the same key exists in two validations the last one wins You pass it a lambda that validates parameters. EXAMPLE: errors = validate_workflows(-> = validate_params(params_),
-> {@update_location_wf = update_location_wf.new(params_)})
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/voom/commands/aggregate_validations.rb', line 14 def aggregate_validations(*lambdas) lambdas.reduce({}) do |errors, lambda| begin lambda.call rescue Errors::ParameterValidation => e errors.merge!(extract_errors(e)) end errors end end |
#aggregate_validations!(*lambdas) ⇒ Object
25 26 27 28 29 |
# File 'lib/voom/commands/aggregate_validations.rb', line 25 def aggregate_validations!(*lambdas) errors = aggregate_validations(*lambdas) trace {errors.inspect} if errors.any? raise Errors::ParameterValidation.new('Form validation failed.', errors) if errors.any? end |