restriction shorthand symbols

This commit is contained in:
Adam Meehan
2010-08-07 19:08:35 +10:00
parent 924c6766c1
commit 82ede60985
4 changed files with 56 additions and 1 deletions

View File

@@ -26,6 +26,13 @@ module ValidatesTimeliness
mattr_accessor :ignore_restriction_errors
@@ignore_restriction_errors = defined?(Rails) ? !Rails.env.test? : false
# Shorthand time and date symbols for restrictions
mattr_accessor :restriction_shorthand_symbols
@@restriction_shorthand_symbols = {
:now => lambda { Time.now },
:today => lambda { Date.today }
}
# Setup method for plugin configuration
def self.setup
yield self

View File

@@ -31,7 +31,11 @@ module ValidatesTimeliness
when String
value.to_time(:local)
when Symbol
evaluate_option_value(record.send(value), record)
if !record.respond_to?(value) && restriction_shorthand?(value)
ValidatesTimeliness.restriction_shorthand_symbols[value].call
else
evaluate_option_value(record.send(value), record)
end
when Proc
result = value.arity > 0 ? value.call(record) : value.call
evaluate_option_value(result, record)
@@ -40,5 +44,9 @@ module ValidatesTimeliness
end
end
def restriction_shorthand?(symbol)
ValidatesTimeliness.restriction_shorthand_symbols.keys.include?(symbol)
end
end
end