Skip to content

Commit

Permalink
update ActiveModel::Validator docs [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Rodriguez committed Jul 29, 2012
1 parent f0f7786 commit 7850267
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/secure_password.rb
Expand Up @@ -11,7 +11,7 @@ module ClassMethods
# you wish to turn off validations, pass <tt>validations: false</tt> as an # you wish to turn off validations, pass <tt>validations: false</tt> as an
# argument. You can add more validations by hand if need be. # argument. You can add more validations by hand if need be.
# #
# You need to add bcrypt-ruby (~> 3.0.0) to Gemfile to use #has_secure_password: # You need to add bcrypt-ruby (~> 3.0.0) to Gemfile to use #has_secure_password:
# #
# gem 'bcrypt-ruby', '~> 3.0.0' # gem 'bcrypt-ruby', '~> 3.0.0'
# #
Expand Down
20 changes: 10 additions & 10 deletions activemodel/lib/active_model/validator.rb
Expand Up @@ -2,7 +2,7 @@
require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/inclusion' require 'active_support/core_ext/object/inclusion'


module ActiveModel #:nodoc: module ActiveModel


# == Active Model Validator # == Active Model Validator
# #
Expand All @@ -28,7 +28,7 @@ module ActiveModel #:nodoc:
# end # end
# #
# Any class that inherits from ActiveModel::Validator must implement a method # Any class that inherits from ActiveModel::Validator must implement a method
# called <tt>validate</tt> which accepts a <tt>record</tt>. # called +validate+ which accepts a +record+.
# #
# class Person # class Person
# include ActiveModel::Validations # include ActiveModel::Validations
Expand All @@ -42,8 +42,8 @@ module ActiveModel #:nodoc:
# end # end
# end # end
# #
# To cause a validation error, you must add to the <tt>record</tt>'s errors directly # To cause a validation error, you must add to the +record+'s errors directly
# from within the validators message # from within the validators message.
# #
# class MyValidator < ActiveModel::Validator # class MyValidator < ActiveModel::Validator
# def validate(record) # def validate(record)
Expand All @@ -63,7 +63,7 @@ module ActiveModel #:nodoc:
# end # end
# #
# The easiest way to add custom validators for validating individual attributes # The easiest way to add custom validators for validating individual attributes
# is with the convenient <tt>ActiveModel::EachValidator</tt>. For example: # is with the convenient <tt>ActiveModel::EachValidator</tt>.
# #
# class TitleValidator < ActiveModel::EachValidator # class TitleValidator < ActiveModel::EachValidator
# def validate_each(record, attribute, value) # def validate_each(record, attribute, value)
Expand All @@ -72,7 +72,7 @@ module ActiveModel #:nodoc:
# end # end
# #
# This can now be used in combination with the +validates+ method # This can now be used in combination with the +validates+ method
# (see <tt>ActiveModel::Validations::ClassMethods.validates</tt> for more on this) # (see <tt>ActiveModel::Validations::ClassMethods.validates</tt> for more on this).
# #
# class Person # class Person
# include ActiveModel::Validations # include ActiveModel::Validations
Expand All @@ -83,8 +83,7 @@ module ActiveModel #:nodoc:
# #
# Validator may also define a +setup+ instance method which will get called # Validator may also define a +setup+ instance method which will get called
# with the class that using that validator as its argument. This can be # with the class that using that validator as its argument. This can be
# useful when there are prerequisites such as an +attr_accessor+ being present # useful when there are prerequisites such as an +attr_accessor+ being present.
# for example:
# #
# class MyValidator < ActiveModel::Validator # class MyValidator < ActiveModel::Validator
# def setup(klass) # def setup(klass)
Expand All @@ -94,15 +93,13 @@ module ActiveModel #:nodoc:
# #
# This setup method is only called when used with validation macros or the # This setup method is only called when used with validation macros or the
# class level <tt>validates_with</tt> method. # class level <tt>validates_with</tt> method.
#
class Validator class Validator
attr_reader :options attr_reader :options


# Returns the kind of the validator. Examples: # Returns the kind of the validator. Examples:
# #
# PresenceValidator.kind # => :presence # PresenceValidator.kind # => :presence
# UniquenessValidator.kind # => :uniqueness # UniquenessValidator.kind # => :uniqueness
#
def self.kind def self.kind
@kind ||= name.split('::').last.underscore.sub(/_validator$/, '').to_sym unless anonymous? @kind ||= name.split('::').last.underscore.sub(/_validator$/, '').to_sym unless anonymous?
end end
Expand All @@ -113,6 +110,9 @@ def initialize(options)
end end


# Return the kind for this validator. # Return the kind for this validator.
#
# PresenceValidator.new.kind # => :presence
# UniquenessValidator.new.kind # => :uniqueness 
def kind def kind
self.class.kind self.class.kind
end end
Expand Down

0 comments on commit 7850267

Please sign in to comment.