mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-24 23:06:42 +00:00
allow for a string column being validated as a date/time
This commit is contained in:
parent
12af4d8d9d
commit
e4760126e2
@ -9,7 +9,7 @@ module ValidatesTimeliness
|
|||||||
:time => '%H:%M:%S',
|
:time => '%H:%M:%S',
|
||||||
:date => '%Y-%m-%d',
|
:date => '%Y-%m-%d',
|
||||||
:datetime => '%Y-%m-%d %H:%M:%S'
|
:datetime => '%Y-%m-%d %H:%M:%S'
|
||||||
}
|
}
|
||||||
|
|
||||||
attr_reader :configuration, :type
|
attr_reader :configuration, :type
|
||||||
|
|
||||||
@ -19,10 +19,9 @@ module ValidatesTimeliness
|
|||||||
@type = @configuration.delete(:type)
|
@type = @configuration.delete(:type)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The main validation method which can be used directly or called through
|
|
||||||
# the other specific type validation methods.
|
|
||||||
def call(record, attr_name)
|
def call(record, attr_name)
|
||||||
value = record.send(attr_name)
|
value = record.send(attr_name)
|
||||||
|
value = record.class.parse_date_time(value, type, false) if value.is_a?(String)
|
||||||
raw_value = raw_value(record, attr_name)
|
raw_value = raw_value(record, attr_name)
|
||||||
|
|
||||||
return if (raw_value.nil? && configuration[:allow_nil]) || (raw_value.blank? && configuration[:allow_blank])
|
return if (raw_value.nil? && configuration[:allow_nil]) || (raw_value.blank? && configuration[:allow_blank])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user