aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations/with.rb
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2010-02-18 22:28:48 +0700
committerJosé Valim <jose.valim@gmail.com>2010-02-21 12:37:46 +0100
commit8f97e9d19abf02b33c5f7c0c1f1d5daf13e28893 (patch)
tree3858a21a27d5c83e67b28722a3b7b9d62c16efa9 /activemodel/lib/active_model/validations/with.rb
parent250c8092461f5e6bf62751b313f6605a37fd1b2b (diff)
downloadrails-8f97e9d19abf02b33c5f7c0c1f1d5daf13e28893.tar.gz
rails-8f97e9d19abf02b33c5f7c0c1f1d5daf13e28893.tar.bz2
rails-8f97e9d19abf02b33c5f7c0c1f1d5daf13e28893.zip
Add validators reflection so you can do 'Person.validators' and 'Person.validators_on(:name)'.
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activemodel/lib/active_model/validations/with.rb')
-rw-r--r--activemodel/lib/active_model/validations/with.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/validations/with.rb b/activemodel/lib/active_model/validations/with.rb
index db563876af..83d3ea80d6 100644
--- a/activemodel/lib/active_model/validations/with.rb
+++ b/activemodel/lib/active_model/validations/with.rb
@@ -62,6 +62,15 @@ module ActiveModel
args.each do |klass|
validator = klass.new(options, &block)
validator.setup(self) if validator.respond_to?(:setup)
+
+ if validator.respond_to?(:attributes) && !validator.attributes.empty?
+ validator.attributes.each do |attribute|
+ _validators[attribute.to_sym] << validator
+ end
+ else
+ _validators[nil] << validator
+ end
+
validate(validator, options)
end
end