Class: ValidationManager

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

Instance Method Summary collapse

Instance Method Details

#validate(obj, profile) ⇒ ValidationManagerResult

Called to validate an object against a validation profile.

Parameters:

  • obj (Object)

    The object to validate

  • profile (ClassName)

    The class name of the validation profile to validate against

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/validation_profiler.rb', line 33

def validate(obj, profile)

  result = ValidationManagerResult.new

  validation_rules = profile.class_variable_get(:@@validation_rules)
  validation_rules.each do |r|

    rule = ValidationRuleManager.instance.get_rule(r[:name])
    outcome = rule.validate(obj, r[:field], r[:attributes])

    if !outcome
      result.outcome = false
      result.errors.push({ field: r[:field], message: rule.error_message(r[:field], r[:attributes]) })
    end

  end

  result

end