Class: ValidationManager

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

Instance Method Summary collapse

Instance Method Details

#validate(obj, profile, parent = nil) ⇒ 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:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/validation_profiler.rb', line 39

def validate(obj, profile, parent = nil)

  result = ValidationManagerResult.new

  validation_rules = profile.class_variable_get(:@@validation_rules)

  validation_rules.each do |r|

    if ValidationRuleManager.instance == nil
      ValidationRuleManager.new
    end

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

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

  end

  result

end