module Voom::Commands::AggregateValidations

Public Instance Methods

aggregate_validations(*lambdas) click to toggle source

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(-> {@params = validate_params(params_)},

-> {@update_location_wf = update_location_wf.new(params_)})
# 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) click to toggle source
# 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