Class: FluentValidation::FluentValidator
- Inherits:
-
Object
- Object
- FluentValidation::FluentValidator
- Defined in:
- lib/fluent_validation/fluent_validator.rb
Instance Method Summary collapse
-
#initialize ⇒ FluentValidator
constructor
A new instance of FluentValidator.
- #rule_for(&expression) ⇒ Object
- #validate(object) ⇒ Object
Constructor Details
#initialize ⇒ FluentValidator
Returns a new instance of FluentValidator.
9 10 11 |
# File 'lib/fluent_validation/fluent_validator.rb', line 9 def initialize @attribute_rules = Array.new end |
Instance Method Details
#rule_for(&expression) ⇒ Object
13 14 15 16 17 |
# File 'lib/fluent_validation/fluent_validator.rb', line 13 def rule_for(&expression) rule = AttributeRule.new(&expression) @attribute_rules << rule RuleBuilder.new(rule) end |
#validate(object) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fluent_validation/fluent_validator.rb', line 19 def validate(object) failures = Array.new @attribute_rules.each do |rule| result = rule.validate object failures.concat result if result.class != Results::ValidationSuccess end Results::ValidationResult.new failures end |