From a63f7a136401b59db52fb802180f6c9793d83bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 20 Jul 2012 14:23:05 -0300 Subject: [PATCH] Update documentation and change the range method name to delimiter. --- activemodel/lib/active_model/validations/clusivity.rb | 10 +++++----- activemodel/lib/active_model/validations/exclusion.rb | 1 + activemodel/lib/active_model/validations/inclusion.rb | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/activemodel/lib/active_model/validations/clusivity.rb b/activemodel/lib/active_model/validations/clusivity.rb index 7f88293220..643a6f2b7c 100644 --- a/activemodel/lib/active_model/validations/clusivity.rb +++ b/activemodel/lib/active_model/validations/clusivity.rb @@ -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 Range#include? on non-numeric ranges checks all possible values in the diff --git a/activemodel/lib/active_model/validations/exclusion.rb b/activemodel/lib/active_model/validations/exclusion.rb index dfeec37ca1..dc3368c569 100644 --- a/activemodel/lib/active_model/validations/exclusion.rb +++ b/activemodel/lib/active_model/validations/exclusion.rb @@ -30,6 +30,7 @@ module HelperMethods # * :in - 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 + # * :within - A synonym(or alias) for :in # Range#cover?, otherwise with include?. # * :message - Specifies a custom error message (default is: "is # reserved"). diff --git a/activemodel/lib/active_model/validations/inclusion.rb b/activemodel/lib/active_model/validations/inclusion.rb index 5a679e0423..c2835c550b 100644 --- a/activemodel/lib/active_model/validations/inclusion.rb +++ b/activemodel/lib/active_model/validations/inclusion.rb @@ -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 Range#cover?, # otherwise with include?. + # * :within - A synonym(or alias) for :in # * :message - Specifies a custom error message (default is: "is # not included in the list"). # * :allow_nil - If set to +true+, skips this validation if the -- GitLab