aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations/inclusion.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-12-23 01:08:27 +0100
committerJosé Valim <jose.valim@gmail.com>2009-12-23 01:08:27 +0100
commit977a5c43b160d8aa8d1b87bb0feb54db85fe203c (patch)
tree41b6e8649aaad96e55ea62ddd6f3053df6da20f1 /activemodel/lib/active_model/validations/inclusion.rb
parentf1085f41287687835659fa23079080204fe32e96 (diff)
downloadrails-977a5c43b160d8aa8d1b87bb0feb54db85fe203c.tar.gz
rails-977a5c43b160d8aa8d1b87bb0feb54db85fe203c.tar.bz2
rails-977a5c43b160d8aa8d1b87bb0feb54db85fe203c.zip
Added check_validity! to EachValidator and refactor existing ones.
Diffstat (limited to 'activemodel/lib/active_model/validations/inclusion.rb')
-rw-r--r--activemodel/lib/active_model/validations/inclusion.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/validations/inclusion.rb b/activemodel/lib/active_model/validations/inclusion.rb
index d42c95357c..a122e9e737 100644
--- a/activemodel/lib/active_model/validations/inclusion.rb
+++ b/activemodel/lib/active_model/validations/inclusion.rb
@@ -1,6 +1,11 @@
module ActiveModel
module Validations
class InclusionValidator < EachValidator
+ def check_validity!
+ raise ArgumentError, "An object with the method include? is required must be supplied as the " <<
+ ":in option of the configuration hash" unless options[:in].respond_to?(:include?)
+ end
+
def validate_each(record, attribute, value)
return if options[:in].include?(value)
record.errors.add(attribute, :inclusion, :default => options[:message], :value => value)
@@ -30,10 +35,6 @@ module ActiveModel
def validates_inclusion_of(*attr_names)
options = attr_names.extract_options!
options[:in] ||= options.delete(:within)
-
- raise ArgumentError, "An object with the method include? is required must be supplied as the " <<
- ":in option of the configuration hash" unless options[:in].respond_to?(:include?)
-
validates_with InclusionValidator, options.merge(:attributes => attr_names)
end
end