module Voom::Commands::ValidateParams

Public Instance Methods

schema() click to toggle source
# File lib/voom/commands/validate_params.rb, line 6
def schema
  raise 'You must implement schema!'
end
validate_params(**params_) click to toggle source
# File lib/voom/commands/validate_params.rb, line 10
def validate_params(**params_)
  result = schema.call(params_.symbolize_keys)
  # trace { result.inspect }
  raise Errors::ParameterValidation.new("Form validation failed: #{humanize(result.messages(full: true))}",
                                        humanize(result.messages(full: true))) if result.failure?
  result.to_h
end

Private Instance Methods

humanize(messages) click to toggle source
# File lib/voom/commands/validate_params.rb, line 20
def humanize(messages)
  messages.map do |key, messages|
    [
        key,
        messages.map do |msg|
          msg.humanize
        end
    ]
  end.to_h
end