aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2010-01-15 08:29:08 +1100
committerMikel Lindsaar <raasdnil@gmail.com>2010-01-15 08:29:08 +1100
commit23e434f08fa756e9a8c472a8212c6f72ac92b32b (patch)
tree467b1a34448c7357c259965dced00e769d3edcf9 /activemodel
parent582228e4355de86ef0a6dc9ce41a3f1da37383f0 (diff)
downloadrails-23e434f08fa756e9a8c472a8212c6f72ac92b32b.tar.gz
rails-23e434f08fa756e9a8c472a8212c6f72ac92b32b.tar.bz2
rails-23e434f08fa756e9a8c472a8212c6f72ac92b32b.zip
ActiveModel::Conversion documentation
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/README10
-rw-r--r--activemodel/lib/active_model/conversion.rb13
2 files changed, 21 insertions, 2 deletions
diff --git a/activemodel/README b/activemodel/README
index 1d987605c0..c0d59f7208 100644
--- a/activemodel/README
+++ b/activemodel/README
@@ -13,7 +13,7 @@ to then present a common interface to the Action Pack helpers.
You can include functionality from the following modules:
-* Callbacks
+* Adding callbacks to your class
class MyClass
extend ActiveModel::Callbacks
@@ -31,3 +31,11 @@ You can include functionality from the following modules:
{Learn more}[link:classes/ActiveModel/CallBacks.html]
+* For classes that already look like an Active Record object
+
+ class MyClass
+ include ActiveModel::Conversion
+ end
+
+ ...returns the class itself when sent :to_model
+
diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb
index d5c65920f6..c14a07c7dc 100644
--- a/activemodel/lib/active_model/conversion.rb
+++ b/activemodel/lib/active_model/conversion.rb
@@ -1,5 +1,16 @@
module ActiveModel
- # Include ActiveModel::Conversion if your object "acts like an ActiveModel model".
+ # If your object is already designed to implement all of the Active Model featurs
+ # include this module in your Class.
+ #
+ # class MyClass
+ # include ActiveModel::Conversion
+ # end
+ #
+ # Returns self to the <tt>:to_model</tt> method.
+ #
+ # 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.
module Conversion
def to_model
self