Module: ValidateMyRoutes::Validate::Rules
- Defined in:
- lib/validate_my_routes/validate/rules.rb,
lib/validate_my_routes/validate/rules/enum.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/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
Overview
Module provides methods to validate if rule is a rule and if it can be used for single or all parameters validation.
Defined Under Namespace
Modules: AllParameters, Anything, Comparable, Compound, Conditional, Enum, OfType, Required, Transforms
Constant Summary collapse
- REQUIRED_RULE_METHODS =
%i[validate! description rule_type].freeze
Class Method Summary collapse
- .all_params_rule?(rule) ⇒ Boolean
- .single_param_rule?(rule) ⇒ Boolean
-
.validate_all_params_rule!(rule) ⇒ Object
Validate that rule can be used for all parameters validation.
-
.validate_single_param_rule!(rule) ⇒ Object
Validate that rule can be used for single parameter validation.
Class Method Details
.all_params_rule?(rule) ⇒ Boolean
25 26 27 |
# File 'lib/validate_my_routes/validate/rules.rb', line 25 def all_params_rule?(rule) validation_rule?(rule) && %i[all_params general].include?(rule.rule_type) end |
.single_param_rule?(rule) ⇒ Boolean
21 22 23 |
# File 'lib/validate_my_routes/validate/rules.rb', line 21 def single_param_rule?(rule) validation_rule?(rule) && %i[single_param general].include?(rule.rule_type) end |
.validate_all_params_rule!(rule) ⇒ Object
Validate that rule can be used for all parameters validation
Example:
Rules.validate_all_params_rule! of_type(Integer) # => throws an exception
46 47 48 49 50 51 |
# File 'lib/validate_my_routes/validate/rules.rb', line 46 def validate_all_params_rule!(rule) return if Rules.all_params_rule?(rule) raise ValidateMyRoutes::Errors::UnsupportedRuleError, "rule #{rule} must implement #{REQUIRED_RULE_METHODS.join(', ')} " \ 'and be either :generic or :all_params rule type.' end |
.validate_single_param_rule!(rule) ⇒ Object
Validate that rule can be used for single parameter validation
Example:
Rules.validate_single_param_rule! required(:q) # => throws an exception
34 35 36 37 38 39 |
# File 'lib/validate_my_routes/validate/rules.rb', line 34 def validate_single_param_rule!(rule) return if Rules.single_param_rule?(rule) raise ValidateMyRoutes::Errors::UnsupportedRuleError, "rule #{rule} must implement #{REQUIRED_RULE_METHODS.join(', ')} " \ 'and be either :generic or :single_param rule type.' end |