Module: ValidateMyRoutes::Validate::RulesCombinators

Included in:
ValidationRule
Defined in:
lib/validate_my_routes/validate/mixins/rules_combinators.rb

Overview

Helper functions to provide a DSL for creating validation rules

Instance Method Summary collapse

Instance Method Details

#and(other_rule) ⇒ Object

Chain rule with another one to perform both validations Note that if first rule fails validation, second is ignored

required.and of_type(Integer)


17
18
19
# File 'lib/validate_my_routes/validate/mixins/rules_combinators.rb', line 17

def and(other_rule)
  ValidateMyRoutes::ValidationRules.and(self, other_rule)
end

#negateObject

Negate the rule to validate opposite expectation

is_an_integer = of_type(Integer)
is_not_an_integer = of_type(Integer).negate


9
10
11
# File 'lib/validate_my_routes/validate/mixins/rules_combinators.rb', line 9

def negate
  ValidateMyRoutes::ValidationRules.not self
end

#or(other_rule) ⇒ Object

Chain rule with another one to perform one or another validations Note that second validation will be performed only if first fails

eql('all').or of_type(Integer)


25
26
27
# File 'lib/validate_my_routes/validate/mixins/rules_combinators.rb', line 25

def or(other_rule)
  ValidateMyRoutes::ValidationRules.or(self, other_rule)
end