Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revised the rest of the files from ActiveModel.

  • Loading branch information...
commit 7d7d54fa1fd000703f142a6b44f4e6f264a35270 1 parent 2572af1
@rizwanreza rizwanreza authored
View
16 activemodel/lib/active_model/translation.rb
@@ -1,9 +1,11 @@
require 'active_support/core_ext/hash/reverse_merge'
module ActiveModel
-
- # ActiveModel::Translation provides integration between your object and
- # the Rails internationalization (i18n) framework.
+
+ # == Active Model Translation
+ #
+ # Provides integration between your object and the Rails internationalization
+ # (i18n) framework.
#
# A minimal implementation could be:
#
@@ -26,14 +28,16 @@ def i18n_scope
:activemodel
end
- # When localizing a string, goes through the lookup returned by this method.
- # Used in ActiveModel::Name#human, ActiveModel::Errors#full_messages and
+ # When localizing a string, it goes through the lookup returned by this
+ # method, which is used in ActiveModel::Name#human,
+ # ActiveModel::Errors#full_messages and
# ActiveModel::Translation#human_attribute_name.
def lookup_ancestors
self.ancestors.select { |x| x.respond_to?(:model_name) }
end
- # Transforms attributes names into a more human format, such as "First name" instead of "first_name".
+ # Transforms attribute names into a more human format, such as "First name"
+ # instead of "first_name".
#
# Person.human_attribute_name("first_name") # => "First name"
#
View
40 activemodel/lib/active_model/validations.rb
@@ -5,7 +5,9 @@
require 'active_model/errors'
module ActiveModel
-
+
+ # == Active Model Validations
+ #
# Provides a full validation framework to your objects.
#
# A minimal implementation could be:
@@ -38,7 +40,7 @@ module ActiveModel
#
# Note that ActiveModel::Validations automatically adds an +errors+ method
# to your instances initialized with a new ActiveModel::Errors object, so
- # there is no need for you to add this manually.
+ # there is no need for you to do this manually.
#
module Validations
extend ActiveSupport::Concern
@@ -71,14 +73,14 @@ module ClassMethods
# end
#
# Options:
- # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>,
- # other options <tt>:create</tt>, <tt>:update</tt>).
+ # * <tt>:on</tt> - Specifies when this validation is active (default is
+ # <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
# * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+.
# * <tt>:allow_blank</tt> - Skip validation if attribute is blank.
- # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
- # occur (e.g. <tt>:if => :allow_validation</tt>, or
- # <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
- # method, proc or string should return or evaluate to a true or false value.
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
+ # if the validation should occur (e.g. <tt>:if => :allow_validation</tt>,
+ # or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The method,
+ # proc or string should return or evaluate to a true or false value.
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
# not occur (e.g. <tt>:unless => :skip_validation</tt>, or
# <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
@@ -104,7 +106,7 @@ def validates_each(*attr_names, &block)
# end
# end
#
- # Or with a block which is passed the current record to be validated:
+ # Or with a block which is passed with the current record to be validated:
#
# class Comment
# include ActiveModel::Validations
@@ -127,7 +129,8 @@ def validate(*args, &block)
set_callback(:validate, *args, &block)
end
- # List all validators that being used to validate the model using +validates_with+ method.
+ # List all validators that are being used to validate the model using
+ # +validates_with+ method.
def validators
_validators.values.flatten.uniq
end
@@ -155,9 +158,9 @@ def errors
@errors ||= Errors.new(self)
end
- # Runs all the specified validations and returns true if no errors were added otherwise false.
- # Context can optionally be supplied to define which callbacks to test against (the context is
- # defined on the validations using :on).
+ # Runs all the specified validations and returns true if no errors were added
+ # otherwise false. Context can optionally be supplied to define which callbacks
+ # to test against (the context is defined on the validations using :on).
def valid?(context = nil)
current_context, self.validation_context = validation_context, context
errors.clear
@@ -167,14 +170,17 @@ def valid?(context = nil)
self.validation_context = current_context
end
- # Performs the opposite of <tt>valid?</tt>. Returns true if errors were added, false otherwise.
+ # Performs the opposite of <tt>valid?</tt>. Returns true if errors were added,
+ # false otherwise.
def invalid?(context = nil)
!valid?(context)
end
- # Hook method defining how an attribute value should be retieved. By default this is assumed
- # to be an instance named after the attribute. Override this method in subclasses should you
- # need to retrieve the value for a given attribute differently e.g.
+ # Hook method defining how an attribute value should be retieved. By default
+ # this is assumed to be an instance named after the attribute. Override this
+ # method in subclasses should you need to retrieve the value for a given
+ # attribute differently:
+ #
# class MyClass
# include ActiveModel::Validations
#
View
3  activemodel/lib/active_model/validator.rb
@@ -3,6 +3,9 @@
require 'active_support/core_ext/object/blank'
module ActiveModel #:nodoc:
+
+ # == Active Model Validator
+ #
# A simple base class that can be used along with
# +ActiveModel::Validations::ClassMethods.validates_with+
#
Please sign in to comment.
Something went wrong with that request. Please try again.