Class: RegexValidationRule
Instance Method Summary
collapse
#get_field_value, #is_required?
Instance Method Details
#error_message(field, attributes = {}) ⇒ Object
286
287
288
289
290
291
292
293
294
|
# File 'lib/validation_profiler/rules/rules.rb', line 286
def error_message(field, attributes = {})
if attributes[:message] == nil
"#{field} is not a valid"
else
attributes[:message]
end
end
|
#validate(obj, field, attributes) ⇒ Object
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
# File 'lib/validation_profiler/rules/rules.rb', line 297
def validate(obj, field, attributes)
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
|