Module: ValidateMyRoutes::Validate
- Defined in:
- lib/validate_my_routes/validate.rb,
lib/validate_my_routes/validate/rules.rb,
lib/validate_my_routes/validate/rules/enum.rb,
lib/validate_my_routes/validate/mixins/macros.rb,
lib/validate_my_routes/validate/rules/of_type.rb,
lib/validate_my_routes/validate/rules/anything.rb,
lib/validate_my_routes/validate/rules/compound.rb,
lib/validate_my_routes/validate/rules/required.rb,
lib/validate_my_routes/validate/convert_to_type.rb,
lib/validate_my_routes/validate/validation_rule.rb,
lib/validate_my_routes/validate/rules/comparable.rb,
lib/validate_my_routes/validate/rules/transforms.rb,
lib/validate_my_routes/validate/rules/conditional.rb,
lib/validate_my_routes/validate/rules/all_parameters.rb,
lib/validate_my_routes/validate/mixins/rules_combinators.rb
Overview
Module for validation. Provides method to validate value by specified rule.
Defined Under Namespace
Modules: ConvertToType, Macros, Rules, RulesCombinators Classes: ValidationRule
Class Method Summary collapse
-
.validate!(app, rule, *args) ⇒ Object
Perform validation of a single rule in-place Note: this method is not validating that rule is for all parameters or just a single Example:.
Class Method Details
.validate!(app, rule, *args) ⇒ Object
Perform validation of a single rule in-place Note: this method is not validating that rule is for all parameters or just a single Example:
get 'some/:id' do |id|
ValidateMyRoutes::Validate.validate!(self, greater_than(5), id.to_i, 'id') do |msg|
halt 400, "Id <#{id}> failed validation: #{msg}"
end
end
17 18 19 20 21 22 23 24 |
# File 'lib/validate_my_routes/validate.rb', line 17 def validate!(app, rule, *args) rule.validate!(app, *args) rescue Errors::ConditionalValidationError false rescue Errors::ValidationError => failure app.halt failure.status_code, failure. unless block_given? yield failure. end |