aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations/clusivity.rb
diff options
context:
space:
mode:
authorGabriel Sobrinho <gabriel.sobrinho@gmail.com>2012-08-12 17:38:22 -0300
committerGabriel Sobrinho <gabriel.sobrinho@gmail.com>2012-08-24 15:26:17 -0300
commit2f3eb484f2712ba1833fea758ee85e49c374fc5b (patch)
tree119c197b8f2b746ed55e6cac2ab2f3d562a2659c /activemodel/lib/active_model/validations/clusivity.rb
parent2c571b3f0544a6457db4818e752f4cd4bacd48b4 (diff)
downloadrails-2f3eb484f2712ba1833fea758ee85e49c374fc5b.tar.gz
rails-2f3eb484f2712ba1833fea758ee85e49c374fc5b.tar.bz2
rails-2f3eb484f2712ba1833fea758ee85e49c374fc5b.zip
Accept a symbol for `:in` option on inclusion and exclusion validators
Diffstat (limited to 'activemodel/lib/active_model/validations/clusivity.rb')
-rw-r--r--activemodel/lib/active_model/validations/clusivity.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/validations/clusivity.rb b/activemodel/lib/active_model/validations/clusivity.rb
index 643a6f2b7c..cf1415b6c2 100644
--- a/activemodel/lib/active_model/validations/clusivity.rb
+++ b/activemodel/lib/active_model/validations/clusivity.rb
@@ -3,11 +3,11 @@ require 'active_support/core_ext/range.rb'
module ActiveModel
module Validations
module Clusivity #:nodoc:
- ERROR_MESSAGE = "An object with the method #include? or a proc or lambda is required, " <<
+ ERROR_MESSAGE = "An object with the method #include? or a proc, lambda or symbol is required, " <<
"and must be supplied as the :in (or :within) option of the configuration hash"
def check_validity!
- unless [:include?, :call].any?{ |method| delimiter.respond_to?(method) }
+ unless delimiter.respond_to?(:include?) || delimiter.respond_to?(:call) || delimiter.respond_to?(:to_sym)
raise ArgumentError, ERROR_MESSAGE
end
end
@@ -15,7 +15,14 @@ module ActiveModel
private
def include?(record, value)
- exclusions = delimiter.respond_to?(:call) ? delimiter.call(record) : delimiter
+ exclusions = if delimiter.respond_to?(:call)
+ delimiter.call(record)
+ elsif delimiter.respond_to?(:to_sym)
+ record.send(delimiter)
+ else
+ delimiter
+ end
+
exclusions.send(inclusion_method(exclusions), value)
end