mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 07:16:41 +00:00
Allow any validated attribute to pass timezone aware check in AR
This commit is contained in:
@@ -20,12 +20,18 @@ module ValidatesTimeliness
|
||||
public
|
||||
|
||||
def timeliness_attribute_timezone_aware?(attr_name)
|
||||
attr_name = attr_name.to_s
|
||||
create_time_zone_conversion_attribute?(attr_name, columns_hash[attr_name])
|
||||
create_time_zone_conversion_attribute?(attr_name, timeliness_column_for_attribute(attr_name))
|
||||
end
|
||||
|
||||
def timeliness_attribute_type(attr_name)
|
||||
columns_hash[attr_name.to_s].type
|
||||
timeliness_column_for_attribute(attr_name).type
|
||||
end
|
||||
|
||||
def timeliness_column_for_attribute(attr_name)
|
||||
columns_hash.fetch(attr_name.to_s) do |attr_name|
|
||||
validation_type = _validators[attr_name.to_sym].find {|v| v.kind == :timeliness }.type
|
||||
::ActiveRecord::ConnectionAdapters::Column.new(attr_name, nil, validation_type.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def define_attribute_methods
|
||||
|
||||
@@ -22,6 +22,10 @@ module ValidatesTimeliness
|
||||
|
||||
RESTRICTION_ERROR_MESSAGE = "Error occurred validating %s for %s restriction:\n%s"
|
||||
|
||||
def self.kind
|
||||
:timeliness
|
||||
end
|
||||
|
||||
def initialize(options)
|
||||
@type = options.delete(:type) || :datetime
|
||||
@allow_nil, @allow_blank = options.delete(:allow_nil), options.delete(:allow_blank)
|
||||
|
||||
Reference in New Issue
Block a user