Module: ValidateMyRoutes::ValidationRules

Defined in:
lib/validate_my_routes/validation_rules.rb

Overview

Mixin to add custom rules to the application.

To create custom rule you can extend your class with ValidationRules:

extend ValidateMyRoutes::ValidationRules

Class Method Summary collapse

Class Method Details

.def_all_params_validator(name, &declarations) ⇒ Object



15
16
17
# File 'lib/validate_my_routes/validation_rules.rb', line 15

def def_all_params_validator(name, &declarations)
  def_validation_rule name, :all_params, &declarations
end

.def_single_param_validator(name, &declarations) ⇒ Object



11
12
13
# File 'lib/validate_my_routes/validation_rules.rb', line 11

def def_single_param_validator(name, &declarations)
  def_validation_rule name, :single_param, &declarations
end

.def_validation_rule(name, typ = :general, &declarations) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/validate_my_routes/validation_rules.rb', line 19

def def_validation_rule(name, typ = :general, &declarations)
  raise Errors::MissingValidationDeclarationBlock unless block_given?
  raise Errors::ValidationRuleNamingConflict, name.to_sym if respond_to? name.to_sym

  rule = ->(*expected) { Validate::ValidationRule.new(name, typ, *expected, declarations) }

  define_method(name, rule)
  define_singleton_method(name, rule)
end