Class: RegexValidationRule
Instance Method Summary
collapse
#get_field_value, #is_required?
Instance Method Details
#error_message(field, attributes = {}) ⇒ Object
278
279
280
281
282
283
284
285
286
|
# File 'lib/validation_profiler/rules/rules.rb', line 278
def error_message(field, attributes = {})
if attributes[:message] == nil
"#{field} is not a valid"
else
attributes[:message]
end
end
|
#validate(obj, field, attributes) ⇒ Object
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
# File 'lib/validation_profiler/rules/rules.rb', line 289
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
|