From d13cd2a7a9d766f450e9a8a7e01f5df54b3dc7b0 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sat, 22 Sep 2012 18:26:00 -0500 Subject: update AR::Validations documentation [ci skip] --- activerecord/lib/active_record/core.rb | 2 +- activerecord/lib/active_record/validations.rb | 23 +++++++++++----------- .../lib/active_record/validations/associated.rb | 2 +- .../lib/active_record/validations/presence.rb | 17 ++++++++-------- .../lib/active_record/validations/uniqueness.rb | 12 +++++------ 5 files changed, 28 insertions(+), 28 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index f97c363871..c01a472d76 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -1,4 +1,4 @@ -require 'active_support/core_ext/hash/indifferent_access' + require 'active_support/core_ext/hash/indifferent_access' require 'active_support/core_ext/object/duplicable' require 'thread' diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index ed561bfb3c..019290725d 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -10,8 +10,8 @@ module ActiveRecord # puts invalid.record.errors # end class RecordInvalid < ActiveRecordError - attr_reader :record - def initialize(record) + attr_reader :recordĀ # :nodoc: + def initialize(record) # :nodoc: @record = record errors = @record.errors.full_messages.join(", ") super(I18n.t(:"#{@record.class.i18n_scope}.errors.messages.record_invalid", :errors => errors, :default => :"errors.messages.record_invalid")) @@ -44,23 +44,24 @@ module ActiveRecord end end - # The validation process on save can be skipped by passing :validate => false. The regular Base#save method is - # replaced with this when the validations module is mixed in, which it is by default. + # The validation process on save can be skipped by passing validate: false. + # The regular Base#save method is replaced with this when the validations + # module is mixed in, which it is by default. def save(options={}) perform_validations(options) ? super : false end - # Attempts to save the record just like Base#save but will raise a +RecordInvalid+ exception instead of returning false - # if the record is not valid. + # Attempts to save the record just like Base#save but will raise a +RecordInvalid+ + # exception instead of returning +false+ if the record is not valid. def save!(options={}) perform_validations(options) ? super : raise(RecordInvalid.new(self)) end - # Runs all the validations within the specified context. Returns true if no errors are found, - # false otherwise. + # Runs all the validations within the specified context. Returns +true+ if + # no errors are found, +false+ otherwise. # - # If the argument is false (default is +nil+), the context is set to :create if - # new_record? is true, and to :update if it is not. + # If the argument is +false+ (default is +nil+), the context is set to :create if + # new_record? is +true+, and to :update if it is not. # # Validations with no :on option will run no matter the context. Validations with # some :on option will only run in the specified context. @@ -72,7 +73,7 @@ module ActiveRecord protected - def perform_validations(options={}) + def perform_validations(options={}) # :nodoc: perform_validation = options[:validate] != false perform_validation ? valid?(options[:context]) : true end diff --git a/activerecord/lib/active_record/validations/associated.rb b/activerecord/lib/active_record/validations/associated.rb index 1fa6629980..7f1972ccf9 100644 --- a/activerecord/lib/active_record/validations/associated.rb +++ b/activerecord/lib/active_record/validations/associated.rb @@ -38,7 +38,7 @@ module ActiveRecord # 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 + # or unless: Proc.new { |user| user.signup_step <= 2 }). The # method, proc or string should return or evaluate to a +true+ or +false+ # value. def validates_associated(*attr_names) diff --git a/activerecord/lib/active_record/validations/presence.rb b/activerecord/lib/active_record/validations/presence.rb index 056527b512..81a3521d24 100644 --- a/activerecord/lib/active_record/validations/presence.rb +++ b/activerecord/lib/active_record/validations/presence.rb @@ -1,6 +1,6 @@ module ActiveRecord module Validations - class PresenceValidator < ActiveModel::Validations::PresenceValidator + class PresenceValidator < ActiveModel::Validations::PresenceValidator # :nodoc: def validate(record) super attributes.each do |attribute| @@ -29,7 +29,7 @@ module ActiveRecord # # If you want to validate the presence of a boolean field (where the real values # are true and false), you will want to use - # validates_inclusion_of :field_name, :in => [true, false]. + # validates_inclusion_of :field_name, in: [true, false]. # # This is due to the way Object#blank? handles boolean values: # false.blank? # => true. @@ -46,16 +46,15 @@ module ActiveRecord # 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. + # 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. + # 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. - # def validates_presence_of(*attr_names) validates_with PresenceValidator, _merge_attributes(attr_names) end diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb index c117872ac8..f3620c1324 100644 --- a/activerecord/lib/active_record/validations/uniqueness.rb +++ b/activerecord/lib/active_record/validations/uniqueness.rb @@ -2,7 +2,7 @@ require 'active_support/core_ext/array/prepend_and_append' module ActiveRecord module Validations - class UniquenessValidator < ActiveModel::EachValidator #:nodoc: + class UniquenessValidator < ActiveModel::EachValidator # :nodoc: def initialize(options) super(options.reverse_merge(:case_sensitive => true)) end @@ -199,7 +199,7 @@ module ActiveRecord # can catch it and restart the transaction (e.g. by telling the user # that the title already exists, and asking him to re-enter the title). # This technique is also known as optimistic concurrency control: - # http://en.wikipedia.org/wiki/Optimistic_concurrency_control + # http://en.wikipedia.org/wiki/Optimistic_concurrency_control. # # The bundled ActiveRecord::ConnectionAdapters distinguish unique index # constraint errors from other types of database errors by throwing an @@ -209,10 +209,10 @@ module ActiveRecord # # The following bundled adapters throw the ActiveRecord::RecordNotUnique exception: # - # * ActiveRecord::ConnectionAdapters::MysqlAdapter - # * ActiveRecord::ConnectionAdapters::Mysql2Adapter - # * ActiveRecord::ConnectionAdapters::SQLite3Adapter - # * ActiveRecord::ConnectionAdapters::PostgreSQLAdapter + # * ActiveRecord::ConnectionAdapters::MysqlAdapter. + # * ActiveRecord::ConnectionAdapters::Mysql2Adapter. + # * ActiveRecord::ConnectionAdapters::SQLite3Adapter. + # * ActiveRecord::ConnectionAdapters::PostgreSQLAdapter. def validates_uniqueness_of(*attr_names) validates_with UniquenessValidator, _merge_attributes(attr_names) end -- cgit v1.2.3