aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations/with.rb
diff options
context:
space:
mode:
authorRizwan Reza <rizwanreza@gmail.com>2010-05-17 02:40:15 +0430
committerRizwan Reza <rizwanreza@gmail.com>2010-05-17 02:40:15 +0430
commitd148a6f6ba5f8ee65905f12cd2601fcc377d4852 (patch)
tree4bcb5e7ad47cfb9a9bb14ffe7c9e003d4646d64c /activemodel/lib/active_model/validations/with.rb
parente1c773006969abea3c0619fbdc7e32c121b6085f (diff)
parent6b4e0cc526f55b5532cf99292c94f0a4db53b16f (diff)
downloadrails-d148a6f6ba5f8ee65905f12cd2601fcc377d4852.tar.gz
rails-d148a6f6ba5f8ee65905f12cd2601fcc377d4852.tar.bz2
rails-d148a6f6ba5f8ee65905f12cd2601fcc377d4852.zip
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activemodel/lib/active_model/validations/with.rb')
-rw-r--r--activemodel/lib/active_model/validations/with.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/validations/with.rb b/activemodel/lib/active_model/validations/with.rb
index 83d3ea80d6..6dbde5bfad 100644
--- a/activemodel/lib/active_model/validations/with.rb
+++ b/activemodel/lib/active_model/validations/with.rb
@@ -1,5 +1,13 @@
module ActiveModel
module Validations
+ module HelperMethods
+ private
+ def _merge_attributes(attr_names)
+ options = attr_names.extract_options!
+ options.merge(:attributes => attr_names.flatten)
+ end
+ end
+
module ClassMethods
# Passes the record off to the class or classes specified and allows them
@@ -75,5 +83,50 @@ module ActiveModel
end
end
end
+
+ # Passes the record off to the class or classes specified and allows them
+ # to add errors based on more complex conditions.
+ #
+ # class Person
+ # include ActiveModel::Validations
+ #
+ # validates :instance_validations
+ #
+ # def instance_validations
+ # validates_with MyValidator
+ # end
+ # end
+ #
+ # Please consult the class method documentation for more information on
+ # creating your own validator.
+ #
+ # You may also pass it multiple classes, like so:
+ #
+ # class Person
+ # include ActiveModel::Validations
+ #
+ # validates :instance_validations, :on => :create
+ #
+ # def instance_validations
+ # validates_with MyValidator, MyOtherValidator
+ # end
+ # end
+ #
+ # Standard configuration options (:on, :if and :unless), which are
+ # available on the class version of validates_with, should instead be
+ # placed on the <tt>validates</tt> method as these are applied and tested
+ # in the callback
+ #
+ # If you pass any additional configuration options, they will be passed
+ # to the class and available as <tt>options</tt>, please refer to the
+ # class version of this method for more information
+ #
+ def validates_with(*args, &block)
+ options = args.extract_options!
+ args.each do |klass|
+ validator = klass.new(options, &block)
+ validator.validate(self)
+ end
+ end
end
end \ No newline at end of file