Class: MatchValidationRule
Instance Method Summary
collapse
#get_field_value, #is_required?
Instance Method Details
#error_message(field, attributes) ⇒ Object
316
317
318
319
320
321
322
323
324
325
326
327
|
# File 'lib/validation_profiler/rules/rules.rb', line 316
def error_message(field, attributes)
match_field = attributes[:field]
if attributes[:message] == nil
"#{field} does not match #{match_field}"
else
attributes[:message]
end
end
|
#validate(obj, field, attributes) ⇒ Object
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
# File 'lib/validation_profiler/rules/rules.rb', line 330
def validate(obj, field, attributes)
field_value = get_field_value(obj, field)
match_field = attributes[:field]
if match_field == nil
raise InvalidRuleAttributes.new(MatchValidationRule, field)
end
if !is_required?(field_value, attributes)
return true
end
match_field_value = get_field_value(obj, match_field)
return field_value == match_field_value
end
|