aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2011-02-20 10:52:24 +0100
committerXavier Noria <fxn@hashref.com>2011-02-20 10:52:49 +0100
commite2d54fb3f17ac30c91d855c45060ec5518b75ec5 (patch)
treeb6bee8f71f2942b4a092648d3bf7f9e963ae47a6 /activemodel/lib
parente984fd43d56797874c532b7d45af8240decfd5ba (diff)
downloadrails-e2d54fb3f17ac30c91d855c45060ec5518b75ec5.tar.gz
rails-e2d54fb3f17ac30c91d855c45060ec5518b75ec5.tar.bz2
rails-e2d54fb3f17ac30c91d855c45060ec5518b75ec5.zip
documents the backported Range#cover?, and related stuff
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/validations/inclusion.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/validations/inclusion.rb b/activemodel/lib/active_model/validations/inclusion.rb
index b0903a6a2c..3ee2a3ccd1 100644
--- a/activemodel/lib/active_model/validations/inclusion.rb
+++ b/activemodel/lib/active_model/validations/inclusion.rb
@@ -14,9 +14,9 @@ module ActiveModel
record.errors.add(attribute, :inclusion, options.except(:in).merge!(:value => value)) unless options[:in].send(include?, value)
end
- # On Ruby 1.9 Range#include? 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.
+ # 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.
def include?
options[:in].is_a?(Range) ? :cover? : :include?
end
@@ -33,6 +33,8 @@ module ActiveModel
#
# Configuration options:
# * <tt>:in</tt> - An enumerable object of available items.
+ # If the enumerable is a range the test is performed with <tt>Range#cover?</tt>
+ # (backported in Active Support for 1.8), otherwise with <tt>include?</tt>.
# * <tt>:message</tt> - Specifies a custom error message (default is: "is not included in the list").
# * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
# * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).