Minor changes to callbacks and conversion API docs.

This commit is contained in:
Rizwan Reza 2010-06-14 13:28:00 +04:30
parent bf7429041e
commit 4523081317
2 changed files with 17 additions and 13 deletions

@ -41,7 +41,7 @@ module ActiveModel
# # Your code here
# end
#
# You can choose not to have all three callbacks by passing an hash to the
# You can choose not to have all three callbacks by passing a hash to the
# define_model_callbacks method.
#
# define_model_callbacks :create, :only => :after, :before
@ -55,13 +55,13 @@ def self.extended(base)
end
end
# define_model_callbacks accepts all options define_callbacks does, in case you
# want to overwrite a default. Besides that, it also accepts an :only option,
# 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 :initializer, :only => :after
#
# Note, the <tt>:only => <type></tt> hash will apply to all callbacks defined on
# Note, the <tt>:only => <type></tt> hash will apply to all call backs defined on
# that method call. To get around this you can call the define_model_callbacks
# method as many times as you need.
#
@ -73,7 +73,7 @@ def self.extended(base)
#
# You can pass in a class to before_<type>, after_<type> and around_<type>, in which
# case the call back will call that class's <action>_<type> method passing the object
# that the callback is being called on.
# that the call back is being called on.
#
# class MyModel
# extend ActiveModel::Callbacks
@ -84,7 +84,7 @@ def self.extended(base)
#
# class AnotherClass
# def self.before_create( obj )
# # obj is the MyModel instance that the callback is being called on
# # obj is the MyModel instance that the call back is being called on
# end
# end
#

@ -1,5 +1,7 @@
module ActiveModel
# Handle default conversions: to_model, to_key and to_param.
# == Active Model Conversions
#
# Handles default conversions: to_model, to_key and to_param.
#
# == Example
#
@ -20,17 +22,19 @@ module ActiveModel
# cm.to_param #=> nil
#
module Conversion
# If your object is already designed to implement all of the Active Model you can use
# the default to_model implementation, which simply returns self.
# If your object is already designed to implement all of the Active Model
# you can use the default to_model implementation, which simply returns
# self.
#
# If your model does not act like an Active Model object, then you should define
# <tt>:to_model</tt> yourself returning a proxy object that wraps your object
# with Active Model compliant methods.
# If your model does not act like an Active Model object, then you should
# define <tt>:to_model</tt> yourself returning a proxy object that wraps
# your object with Active Model compliant methods.
def to_model
self
end
# Returns an Enumerable of all (primary) key attributes or nil if persisted? is false
# Returns an Enumerable of all (primary) key attributes or nil if
# persisted? is false
def to_key
persisted? ? [id] : nil
end