Class: ListValidationRule
Instance Method Summary
collapse
#get_field_value, #is_required?
Instance Method Details
#error_message(field, attributes = {}) ⇒ Object
477
478
479
480
481
482
483
484
485
|
# File 'lib/validation_profiler/rules/rules.rb', line 477
def error_message(field, attributes = {})
if attributes[:message] == nil
"#{field} is not an accepted value."
else
attributes[:message]
end
end
|
#validate(obj, field, attributes = {}) ⇒ Object
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
|
# File 'lib/validation_profiler/rules/rules.rb', line 488
def validate(obj, field, attributes = {})
field_value = get_field_value(obj, field)
if !is_required?(field_value, attributes)
return true
end
list = attributes[:list]
if list == nil || !list.is_a?(Array)
raise InvalidRuleAttributes.new(ListValidationRule, field)
end
if !list.include?(field_value)
return false
end
return true
end
|