Class: FluentValidation::FluentValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent_validation/fluent_validator.rb

Instance Method Summary collapse

Constructor Details

#initializeFluentValidator

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