From 53edd3268461a063979221f896c77f1b42edda67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 20 Jul 2012 13:53:31 -0300 Subject: `validates_inclusion_of` and `validates_exclusion_of` now accept `:within` option as alias of `:in` as documented. Fix #7118 --- activemodel/lib/active_model/validations/clusivity.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'activemodel/lib/active_model/validations') diff --git a/activemodel/lib/active_model/validations/clusivity.rb b/activemodel/lib/active_model/validations/clusivity.rb index 676457ec0f..7f88293220 100644 --- a/activemodel/lib/active_model/validations/clusivity.rb +++ b/activemodel/lib/active_model/validations/clusivity.rb @@ -7,7 +7,7 @@ module ActiveModel "and must be supplied as the :in option of the configuration hash" def check_validity! - unless [:include?, :call].any?{ |method| options[:in].respond_to?(method) } + unless [:include?, :call].any?{ |method| range.respond_to?(method) } raise ArgumentError, ERROR_MESSAGE end end @@ -15,11 +15,14 @@ module ActiveModel private def include?(record, value) - delimiter = options[:in] - exclusions = delimiter.respond_to?(:call) ? delimiter.call(record) : delimiter + exclusions = range.respond_to?(:call) ? range.call(record) : range exclusions.send(inclusion_method(exclusions), value) end + def range + @range ||= options[:in] || options[:within] + end + # In Ruby 1.9 Range#include? on non-numeric ranges checks all possible values in the # range for equality, so it may be slow for large ranges. The new Range#cover? # uses the previous logic of comparing a value with the range endpoints. -- cgit v1.2.3