Allow any validated attribute to pass timezone aware check in AR

This commit is contained in:
Adam Meehan
2012-08-09 12:53:29 +10:00
parent fd73c4eccd
commit 62557e7e04
3 changed files with 41 additions and 5 deletions

View File

@@ -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

View File

@@ -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)