Update documentation and change the range method name to delimiter.

上级 770fa81b
......@@ -4,10 +4,10 @@ module ActiveModel
module Validations
module Clusivity #:nodoc:
ERROR_MESSAGE = "An object with the method #include? or a proc or lambda is required, " <<
"and must be supplied as the :in option of the configuration hash"
"and must be supplied as the :in (or :within) option of the configuration hash"
def check_validity!
unless [:include?, :call].any?{ |method| range.respond_to?(method) }
unless [:include?, :call].any?{ |method| delimiter.respond_to?(method) }
raise ArgumentError, ERROR_MESSAGE
end
end
......@@ -15,12 +15,12 @@ def check_validity!
private
def include?(record, value)
exclusions = range.respond_to?(:call) ? range.call(record) : range
exclusions = delimiter.respond_to?(:call) ? delimiter.call(record) : delimiter
exclusions.send(inclusion_method(exclusions), value)
end
def range
@range ||= options[:in] || options[:within]
def delimiter
@delimiter ||= options[:in] || options[:within]
end
# In Ruby 1.9 <tt>Range#include?</tt> on non-numeric ranges checks all possible values in the
......
......@@ -30,6 +30,7 @@ module HelperMethods
# * <tt>:in</tt> - An enumerable object of items that the value shouldn't
# be part of. This can be supplied as a proc or lambda which returns an
# enumerable. If the enumerable is a range the test is performed with
# * <tt>:within</tt> - A synonym(or alias) for <tt>:in</tt>
# <tt>Range#cover?</tt>, otherwise with <tt>include?</tt>.
# * <tt>:message</tt> - Specifies a custom error message (default is: "is
# reserved").
......
......@@ -30,6 +30,7 @@ module HelperMethods
# supplied as a proc or lambda which returns an enumerable. If the
# enumerable is a range the test is performed with <tt>Range#cover?</tt>,
# otherwise with <tt>include?</tt>.
# * <tt>:within</tt> - A synonym(or alias) for <tt>:in</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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册