aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-06-22 00:32:54 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-06-22 00:32:54 -0500
commitd569bfed0d672ec62627ad6fa3fb89ddda7b6448 (patch)
tree8ae01dda5cb4fd8fcb185b6cccc097958189057f /activemodel
parentc3025e8d597bc17c9fae7c40413af4a98589a930 (diff)
downloadrails-d569bfed0d672ec62627ad6fa3fb89ddda7b6448.tar.gz
rails-d569bfed0d672ec62627ad6fa3fb89ddda7b6448.tar.bz2
rails-d569bfed0d672ec62627ad6fa3fb89ddda7b6448.zip
update ActiveModel::Callbacks documentation [ci skip]
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/callbacks.rb50
1 files changed, 26 insertions, 24 deletions
diff --git a/activemodel/lib/active_model/callbacks.rb b/activemodel/lib/active_model/callbacks.rb
index ebb4b51aa3..b8ba1a0a52 100644
--- a/activemodel/lib/active_model/callbacks.rb
+++ b/activemodel/lib/active_model/callbacks.rb
@@ -6,7 +6,7 @@ module ActiveModel
# Provides an interface for any class to have Active Record like callbacks.
#
# Like the Active Record methods, the callback chain is aborted as soon as
- # one of the methods in the chain returns false.
+ # one of the methods in the chain returns +false+.
#
# First, extend ActiveModel::Callbacks from the class you are creating:
#
@@ -18,9 +18,10 @@ module ActiveModel
#
# define_model_callbacks :create, :update
#
- # This will provide all three standard callbacks (before, around and after) for
- # both the :create and :update methods. To implement, you need to wrap the methods
- # you want callbacks on in a block so that the callbacks get a chance to fire:
+ # This will provide all three standard callbacks (before, around and after)
+ # for both the <tt>:create</tt> and <tt>:update</tt> methods. To implement,
+ # you need to wrap the methods you want callbacks on in a block so that the
+ # callbacks get a chance to fire:
#
# def create
# run_callbacks :create do
@@ -28,8 +29,8 @@ module ActiveModel
# end
# end
#
- # Then in your class, you can use the +before_create+, +after_create+ and +around_create+
- # methods, just as you would in an Active Record module.
+ # Then in your class, you can use the +before_create+, +after_create+ and
+ # +around_create+ methods, just as you would in an Active Record module.
#
# before_create :action_before_create
#
@@ -38,12 +39,12 @@ module ActiveModel
# end
#
# You can choose not to have all three callbacks by passing a hash to the
- # define_model_callbacks method.
+ # +define_model_callbacks+ method.
#
- # define_model_callbacks :create, :only => [:after, :before]
+ # define_model_callbacks :create, only: [:after, :before]
#
- # Would only create the after_create and before_create callback methods in your
- # class.
+ # Would only create the +after_create+ and +before_create+ callback methods in
+ # your class.
module Callbacks
def self.extended(base)
base.class_eval do
@@ -51,25 +52,27 @@ module ActiveModel
end
end
- # define_model_callbacks accepts the same options define_callbacks does, in case
- # you want to overwrite a default. Besides that, it also accepts an :only option,
- # where you can choose if you want all types (before, around or after) or just some.
+ # define_model_callbacks accepts the same options +define_callbacks+ does,
+ # in case you want to overwrite a default. Besides that, it also accepts an
+ # <tt>:only</tt> option, where you can choose if you want all types (before,
+ # around or after) or just some.
#
- # define_model_callbacks :initializer, :only => :after
+ # define_model_callbacks :initializer, only: :after
#
- # Note, the <tt>:only => <type></tt> hash will apply to all callbacks defined on
- # that method call. To get around this you can call the define_model_callbacks
+ # Note, the <tt>only: <type></tt> hash will apply to all callbacks defined
+ # on that method call. To get around this you can call the define_model_callbacks
# method as many times as you need.
#
- # define_model_callbacks :create, :only => :after
- # define_model_callbacks :update, :only => :before
- # define_model_callbacks :destroy, :only => :around
+ # define_model_callbacks :create, only: :after
+ # define_model_callbacks :update, only: :before
+ # define_model_callbacks :destroy, only: :around
#
- # Would create +after_create+, +before_update+ and +around_destroy+ methods only.
+ # Would create +after_create+, +before_update+ and +around_destroy+ methods
+ # only.
#
- # You can pass in a class to before_<type>, after_<type> and around_<type>, in which
- # case the callback will call that class's <action>_<type> method passing the object
- # that the callback is being called on.
+ # You can pass in a class to before_<type>, after_<type> and around_<type>,
+ # in which case the callback will call that class's <action>_<type> method
+ # passing the object that the callback is being called on.
#
# class MyModel
# extend ActiveModel::Callbacks
@@ -83,7 +86,6 @@ module ActiveModel
# # obj is the MyModel instance that the callback is being called on
# end
# end
- #
def define_model_callbacks(*callbacks)
options = callbacks.extract_options!
options = {