From 007c3d8bcb695c3a712b85eb882c95a940c8875e Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Wed, 16 May 2012 00:03:03 -0500 Subject: better example format in validates_exclusion_of docs --- activemodel/lib/active_model/validations/exclusion.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activemodel/lib/active_model/validations/exclusion.rb') diff --git a/activemodel/lib/active_model/validations/exclusion.rb b/activemodel/lib/active_model/validations/exclusion.rb index 5fedb1978b..310e07f897 100644 --- a/activemodel/lib/active_model/validations/exclusion.rb +++ b/activemodel/lib/active_model/validations/exclusion.rb @@ -1,7 +1,6 @@ require "active_model/validations/clusivity" module ActiveModel - # == Active Model Exclusion Validator module Validations class ExclusionValidator < EachValidator @@ -21,7 +20,8 @@ module ActiveModel # validates_exclusion_of :username, :in => %w( admin superuser ), :message => "You don't belong here" # validates_exclusion_of :age, :in => 30..60, :message => "This site is only for under 30 and over 60" # validates_exclusion_of :format, :in => %w( mov avi ), :message => "extension %{value} is not allowed" - # validates_exclusion_of :password, :in => lambda { |p| [p.username, p.first_name] }, :message => "should not be the same as your username or first name" + # validates_exclusion_of :password, :in => lambda { |p| [p.username, p.first_name] }, + # :message => "should not be the same as your username or first name" # end # # Configuration options: -- cgit v1.2.3 From 95e14d1523ae075a39ce6c6efe68b13db43a16d8 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Wed, 16 May 2012 01:23:46 -0500 Subject: better format and fixes to validators docs --- .../lib/active_model/validations/exclusion.rb | 44 +++++++++++++--------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'activemodel/lib/active_model/validations/exclusion.rb') diff --git a/activemodel/lib/active_model/validations/exclusion.rb b/activemodel/lib/active_model/validations/exclusion.rb index 310e07f897..4a6a45ecf3 100644 --- a/activemodel/lib/active_model/validations/exclusion.rb +++ b/activemodel/lib/active_model/validations/exclusion.rb @@ -14,35 +14,45 @@ module ActiveModel end module HelperMethods - # Validates that the value of the specified attribute is not in a particular enumerable object. + # Validates that the value of the specified attribute is not in a + # particular enumerable object. # # class Person < ActiveRecord::Base - # validates_exclusion_of :username, :in => %w( admin superuser ), :message => "You don't belong here" - # validates_exclusion_of :age, :in => 30..60, :message => "This site is only for under 30 and over 60" - # validates_exclusion_of :format, :in => %w( mov avi ), :message => "extension %{value} is not allowed" + # validates_exclusion_of :username, :in => %w( admin superuser ), + # :message => "You don't belong here" + # validates_exclusion_of :age, :in => 30..60, + # :message => "This site is only for under 30 and over 60" + # validates_exclusion_of :format, :in => %w( mov avi ), + # :message => "extension %{value} is not allowed" # validates_exclusion_of :password, :in => lambda { |p| [p.username, p.first_name] }, # :message => "should not be the same as your username or first name" # end # # Configuration options: - # * :in - An enumerable object of items that the value shouldn't be part of. - # This can be supplied as a proc or lambda which returns an enumerable. If the enumerable - # is a range the test is performed with Range#cover? - # (backported in Active Support for 1.8), otherwise with include?. - # * :message - Specifies a custom error message (default is: "is reserved"). - # * :allow_nil - If set to true, skips this validation if the attribute is +nil+ (default is +false+). - # * :allow_blank - If set to true, skips this validation if the attribute is blank (default is +false+). + # * :in - An enumerable object of items that the value shouldn't be + # part of. This can be supplied as a proc or lambda which returns an + # enumerable. If the enumerable is a range the test is performed with + # Range#cover? (backported in Active Support for 1.8), otherwise + # with include?. + # * :message - Specifies a custom error message (default is: "is + # reserved"). + # * :allow_nil - If set to true, skips this validation if the attribute + # is +nil+ (default is +false+). + # * :allow_blank - If set to true, skips this validation if the + # attribute is blank(default is +false+). # * :on - Specifies when this validation is active. Runs in all # validation contexts by default (+nil+), other options are :create # and :update. - # * :if - Specifies a method, proc or string to call to determine if the validation should - # occur (e.g. :if => :allow_validation, or :if => Proc.new { |user| user.signup_step > 2 }). The - # method, proc or string should return or evaluate to a true or false value. - # * :unless - Specifies a method, proc or string to call to determine if the validation should - # not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The + # * :if - Specifies a method, proc or string to call to determine if + # the validation should occur (e.g. :if => :allow_validation, or + # :if => Proc.new { |user| user.signup_step > 2 }). The method, proc + # or string should return or evaluate to a true or false value. + # * :unless - Specifies a method, proc or string to call to determine + # if the validation should not occur (e.g. :unless => :skip_validation, + # or :unless => Proc.new { |user| user.signup_step <= 2 }). The # method, proc or string should return or evaluate to a true or false value. # * :strict - Specifies whether validation should be strict. - # See ActiveModel::Validation#validates! for more information + # See ActiveModel::Validation#validates! for more information. def validates_exclusion_of(*attr_names) validates_with ExclusionValidator, _merge_attributes(attr_names) end -- cgit v1.2.3 From 3004bc24706ed62ea7e4e752adc287dc92d168f5 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Wed, 16 May 2012 10:01:43 -0500 Subject: fixing removed empty lines and examples --- activemodel/lib/active_model/validations/exclusion.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'activemodel/lib/active_model/validations/exclusion.rb') diff --git a/activemodel/lib/active_model/validations/exclusion.rb b/activemodel/lib/active_model/validations/exclusion.rb index 4a6a45ecf3..4f09679541 100644 --- a/activemodel/lib/active_model/validations/exclusion.rb +++ b/activemodel/lib/active_model/validations/exclusion.rb @@ -1,6 +1,7 @@ require "active_model/validations/clusivity" module ActiveModel + # == Active Model Exclusion Validator module Validations class ExclusionValidator < EachValidator @@ -18,12 +19,9 @@ module ActiveModel # particular enumerable object. # # class Person < ActiveRecord::Base - # validates_exclusion_of :username, :in => %w( admin superuser ), - # :message => "You don't belong here" - # validates_exclusion_of :age, :in => 30..60, - # :message => "This site is only for under 30 and over 60" - # validates_exclusion_of :format, :in => %w( mov avi ), - # :message => "extension %{value} is not allowed" + # validates_exclusion_of :username, :in => %w( admin superuser ), :message => "You don't belong here" + # validates_exclusion_of :age, :in => 30..60, :message => "This site is only for under 30 and over 60" + # validates_exclusion_of :format, :in => %w( mov avi ), :message => "extension %{value} is not allowed" # validates_exclusion_of :password, :in => lambda { |p| [p.username, p.first_name] }, # :message => "should not be the same as your username or first name" # end -- cgit v1.2.3