class Launch::Validators::Params

Defined in:

launch/validators/params.cr

Constructors

Instance Method Summary

Macro Summary

Instance methods inherited from class Object

blank? blank?, present? present?

Constructor Detail

def self.new(raw_params : Launch::Router::Params) #

[View source]

Instance Method Detail

def add_rule(rule : BaseRule) #

Validates each field with a given set of predicates returns true if the field is valid otherwise returns false

required(:email) { |p| p.email? & p.size.between? 1..10 }

[View source]
def errors : Array(Launch::Validators::Error) #

[View source]
def params : Hash(String, String?) #

[View source]
def raw_params : Launch::Router::Params #

[View source]
def rules : Array(Launch::Validators::BaseRule) #

[View source]
def to_h : Hash(String, String?) #

[View source]
def to_unsafe_h #

[View source]
def valid? #

Returns True or false whether the validation passed

unless params.valid?
  response.puts {errors: params.errors}.to_json
  response.status_code 400
end

[View source]
def validate! #

Input must be valid otherwise raises error, if valid returns a hash of validated params Otherwise raises a Validator::ValidationFailed error messages contain errors.

user = User.new params.validate!

[View source]
def validation(&) #

Setups validation rules to be performed

params.validation do
  required(:email) { |p| p.url? }
  required(:age, UInt32)
end

[View source]

Macro Detail

macro method_missing(call) #

This will allow params to respond to HTTP::Params methods. For example: [], []?, add, delete, each, fetch, etc.


[View source]