aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations/clusivity.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-07-20 13:53:31 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-07-20 13:53:31 -0300
commit53edd3268461a063979221f896c77f1b42edda67 (patch)
tree1869d01d1a4392692ad448acf3a63ee75f81246a /activemodel/lib/active_model/validations/clusivity.rb
parentf3e4d2097d5f2218e86afd8acf1a3b0574798018 (diff)
downloadrails-53edd3268461a063979221f896c77f1b42edda67.tar.gz
rails-53edd3268461a063979221f896c77f1b42edda67.tar.bz2
rails-53edd3268461a063979221f896c77f1b42edda67.zip
`validates_inclusion_of` and `validates_exclusion_of` now accept
`:within` option as alias of `:in` as documented. Fix #7118
Diffstat (limited to 'activemodel/lib/active_model/validations/clusivity.rb')
-rw-r--r--activemodel/lib/active_model/validations/clusivity.rb9
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.