1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

minor edits and remove mixed titles in AM::Validations docs [ci skip]

This commit is contained in:
Francesco Rodriguez 2012-10-25 20:41:35 -05:00
parent 65be1a0e7a
commit 9ac095fef5
9 changed files with 13 additions and 21 deletions

View file

@ -1,8 +1,7 @@
module ActiveModel
# == Active \Model Acceptance \Validator
module Validations
class AcceptanceValidator < EachValidator #:nodoc:
class AcceptanceValidator < EachValidator # :nodoc:
def initialize(options)
super({ :allow_nil => true, :accept => "1" }.merge!(options))
end
@ -27,7 +26,7 @@ module ActiveModel
#
# class Person < ActiveRecord::Base
# validates_acceptance_of :terms_of_service
# validates_acceptance_of :eula, message: "must be abided"
# validates_acceptance_of :eula, message: 'must be abided'
# end
#
# If the database column does not exist, the +terms_of_service+ attribute

View file

@ -1,8 +1,7 @@
module ActiveModel
# == Active \Model Confirmation \Validator
module Validations
class ConfirmationValidator < EachValidator #:nodoc:
class ConfirmationValidator < EachValidator # :nodoc:
def validate_each(record, attribute, value)
if (confirmed = record.send("#{attribute}_confirmation")) && (value != confirmed)
human_attribute_name = record.class.human_attribute_name(attribute)

View file

@ -2,9 +2,8 @@ require "active_model/validations/clusivity"
module ActiveModel
# == Active \Model Exclusion \Validator
module Validations
class ExclusionValidator < EachValidator #:nodoc:
class ExclusionValidator < EachValidator # :nodoc:
include Clusivity
def validate_each(record, attribute, value)

View file

@ -1,8 +1,7 @@
module ActiveModel
# == Active Model Format Validator
module Validations
class FormatValidator < EachValidator #:nodoc:
class FormatValidator < EachValidator # :nodoc:
def validate_each(record, attribute, value)
if options[:with]
regexp = option_call(record, :with)

View file

@ -2,9 +2,8 @@ require "active_model/validations/clusivity"
module ActiveModel
# == Active \Model Inclusion \Validator
module Validations
class InclusionValidator < EachValidator #:nodoc:
class InclusionValidator < EachValidator # :nodoc:
include Clusivity
def validate_each(record, attribute, value)

View file

@ -1,6 +1,5 @@
module ActiveModel
# == Active \Model Numericality \Validator
module Validations
class NumericalityValidator < EachValidator # :nodoc:
CHECKS = { :greater_than => :>, :greater_than_or_equal_to => :>=,
@ -126,7 +125,7 @@ module ActiveModel
# For example:
#
# class Person < ActiveRecord::Base
# validates_numericality_of :width, less_than: Proc.new { |person| person.height }
# validates_numericality_of :width, less_than: ->(person) { person.height }
# validates_numericality_of :width, greater_than: :minimum_weight
# end
def validates_numericality_of(*attr_names)

View file

@ -1,7 +1,6 @@
module ActiveModel
# == Active \Model Presence \Validator
module Validations
class PresenceValidator < EachValidator # :nodoc:
def validate(record)

View file

@ -1,7 +1,6 @@
require 'active_support/core_ext/hash/slice'
module ActiveModel
# == Active Model validates method
module Validations
module ClassMethods
# This method is a shortcut to all default validators and any custom
@ -129,15 +128,15 @@ module ActiveModel
# the validation itself.
#
# class Person
#  include ActiveModel::Validations
# include ActiveModel::Validations
#
# attr_accessor :name
# validates! :name, presence: true
# end
#
# person = Person.new
#  person.name = ''
#  person.valid?
# person.name = ''
# person.valid?
# # => ActiveModel::StrictValidationFailed: Name can't be blank
def validates!(*attributes)
options = attributes.extract_options!
@ -149,11 +148,11 @@ module ActiveModel
# When creating custom validators, it might be useful to be able to specify
# additional default keys. This can be done by overwriting this method.
def _validates_default_keys #:nodoc:
def _validates_default_keys # :nodoc:
[:if, :unless, :on, :allow_blank, :allow_nil , :strict]
end
def _parse_validates_options(options) #:nodoc:
def _parse_validates_options(options) # :nodoc:
case options
when TrueClass
{}

View file

@ -10,7 +10,7 @@ module ActiveModel
end
end
class WithValidator < EachValidator #:nodoc:
class WithValidator < EachValidator # :nodoc:
def validate_each(record, attr, val)
method_name = options[:with]