class Launch::Validators::Params
- Launch::Validators::Params
- Reference
- Object
Defined in:
launch/validators/params.crConstructors
Instance Method Summary
-
#add_rule(rule : BaseRule)
Validates each field with a given set of predicates returns true if the field is valid otherwise returns false
- #errors : Array(Launch::Validators::Error)
- #params : Hash(String, String?)
- #raw_params : Launch::Router::Params
- #rules : Array(Launch::Validators::BaseRule)
- #to_h : Hash(String, String?)
- #to_unsafe_h
-
#valid?
Returns True or false whether the validation passed
-
#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.
-
#validation(&)
Setups validation rules to be performed
Macro Summary
-
method_missing(call)
This will allow params to respond to HTTP::Params methods.
Constructor Detail
Instance Method Detail
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 }
Returns True or false whether the validation passed
unless params.valid?
response.puts {errors: params.errors}.to_json
response.status_code 400
end
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!
Setups validation rules to be performed
params.validation do
required(:email) { |p| p.url? }
required(:age, UInt32)
end
Macro Detail
This will allow params to respond to HTTP::Params methods. For example: [], []?, add, delete, each, fetch, etc.