Class: RegexValidationRule
Instance Method Summary
collapse
#get_field_value, #is_required?
Instance Method Details
#error_message(field, attributes = {}, parent = nil) ⇒ Object
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
# File 'lib/validation_profiler/rules/rules.rb', line 327
def error_message(field, attributes = {}, parent = nil)
field_name = field.to_s
if parent != nil
field_name = "#{parent.to_s}.#{field.to_s}"
end
if attributes[:message] == nil
"#{field_name} is not a valid"
else
attributes[:message]
end
end
|
#validate(obj, field, attributes, parent = nil) ⇒ Object
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
# File 'lib/validation_profiler/rules/rules.rb', line 344
def validate(obj, field, attributes, parent = nil)
field_value = get_field_value(obj, field)
regex = attributes[:regex]
if regex == nil
raise InvalidRuleAttributes.new(RegexValidationRule, field)
end
if !is_required?(field_value, attributes)
return true
end
if field_value =~ regex
return true
end
return false
end
|