From 92160219a8bf17bd435252304319c094e56e5849 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Tue, 11 May 2010 15:36:09 +0200 Subject: =?UTF-8?q?minor=20changes=20to=20instance=20level=20validations?= =?UTF-8?q?=20implementation=20based=20on=20feedback=20from=20Jos=C3=A9=20?= =?UTF-8?q?Valim?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/active_model/validations/helper_methods.rb | 12 ------- activemodel/lib/active_model/validations/with.rb | 37 +++++++--------------- 2 files changed, 12 insertions(+), 37 deletions(-) delete mode 100644 activemodel/lib/active_model/validations/helper_methods.rb (limited to 'activemodel/lib/active_model/validations') diff --git a/activemodel/lib/active_model/validations/helper_methods.rb b/activemodel/lib/active_model/validations/helper_methods.rb deleted file mode 100644 index 4c709b1fa9..0000000000 --- a/activemodel/lib/active_model/validations/helper_methods.rb +++ /dev/null @@ -1,12 +0,0 @@ -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 - end -end \ No newline at end of file diff --git a/activemodel/lib/active_model/validations/with.rb b/activemodel/lib/active_model/validations/with.rb index 2a2d0d55b4..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 @@ -89,18 +97,8 @@ module ActiveModel # end # end # - # class MyValidator < ActiveModel::Validator - # def validate(record) - # if some_complex_logic - # record.errors[:base] << "This record is invalid" - # end - # end - # - # private - # def some_complex_logic - # # ... - # 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: # @@ -120,24 +118,13 @@ module ActiveModel # in the callback # # If you pass any additional configuration options, they will be passed - # to the class and available as options: - # - # class Person - # include ActiveModel::Validations - # validates_with MyValidator, :my_custom_key => "my custom value" - # end - # - # class MyValidator < ActiveModel::Validator - # def validate(record) - # options[:my_custom_key] # => "my custom value" - # end - # end + # to the class and available as options, 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.setup(self) if validator.respond_to?(:setup) validator.validate(self) end end -- cgit v1.2.3