diff options
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/validations/clusivity.rb | 9 |
1 files changed, 6 insertions, 3 deletions
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 <tt>Range#include?</tt> on non-numeric ranges checks all possible values in the # range for equality, so it may be slow for large ranges. The new <tt>Range#cover?</tt> # uses the previous logic of comparing a value with the range endpoints. |