56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/lore/validation/parameter_validator.rb', line 56
def self.validate_update(klass, value_hash)
Lore.logger.debug { "Validating attributes for updating #{klass.to_s}: " }
Lore.logger.debug { "#{value_hash.inspect}" }
invalid_params = Hash.new
attribute_settings = klass.__attributes__
constraints = attribute_settings.constraints
required = attribute_settings.required
value_hash.each_pair { |table, attributes|
types = attribute_settings.types[table]
if !types then
raise ::Exception.new("No types given for #{klass.to_s} (#{table})")
end
types.delete_if { |attribute,value| !attributes[attribute] }
begin
validate_types(types, attributes, required[table])
rescue Lore::Exceptions::Invalid_Types => ip
invalid_params[table] = ip
end
}
value_hash.each_pair { |table, attributes|
constraints = attribute_settings.constraints[table]
if constraints then
constraints.delete_if { |attribute,constraint| !attributes[attribute] }
begin
validate_constraints(constraints, attributes)
rescue Lore::Exceptions::Unmet_Constraints => ip
invalid_params[table] = ip
end
else
Lore.logger.info { "No constraints for #{klass.to_s}?" }
end
}
if invalid_params.length == 0 then return true end
raise Lore::Exceptions::Validation_Failure.new(klass, invalid_params)
end
|