mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
tiny tweaks
This commit is contained in:
parent
cbb03f0f82
commit
f2f1e0b165
@ -44,15 +44,13 @@ module ValidatesTimeliness
|
|||||||
value = parse(raw_value) if value.is_a?(String) || options[:format]
|
value = parse(raw_value) if value.is_a?(String) || options[:format]
|
||||||
value = type_cast_value(value, @type)
|
value = type_cast_value(value, @type)
|
||||||
|
|
||||||
if value.blank?
|
return add_error(record, attr_name, :"invalid_#{@type}") if value.blank?
|
||||||
return add_error(record, attr_name, :"invalid_#{@type}")
|
|
||||||
end
|
|
||||||
|
|
||||||
@restrictions_to_check.each do |restriction|
|
@restrictions_to_check.each do |restriction|
|
||||||
begin
|
begin
|
||||||
restriction_value = type_cast_value(evaluate_option_value(options[restriction], record), @type)
|
restriction_value = type_cast_value(evaluate_option_value(options[restriction], record), @type)
|
||||||
unless value.send(RESTRICTIONS[restriction], restriction_value)
|
unless value.send(RESTRICTIONS[restriction], restriction_value)
|
||||||
return add_error(record, attr_name, restriction, format_error_value(restriction_value))
|
return add_error(record, attr_name, restriction, restriction_value)
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
unless ValidatesTimeliness.ignore_restriction_errors
|
unless ValidatesTimeliness.ignore_restriction_errors
|
||||||
@ -63,6 +61,7 @@ module ValidatesTimeliness
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_error(record, attr_name, message, value=nil)
|
def add_error(record, attr_name, message, value=nil)
|
||||||
|
value = format_error_value(value) if value
|
||||||
message_options = { :message => options[:"#{message}_message"], :restriction => value }
|
message_options = { :message => options[:"#{message}_message"], :restriction => value }
|
||||||
record.errors.add(attr_name, message, message_options)
|
record.errors.add(attr_name, message, message_options)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user