Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing documentation for ActiveModel::Observer

  • Loading branch information...
commit e6063282f98b9d40da00897727e5ae01ca61b9fc 1 parent fbc7c2b
Mikel Lindsaar mikel authored
Showing with 21 additions and 8 deletions.
  1. +8 −0 activemodel/README
  2. +13 −8 activemodel/lib/active_model/observing.rb
8 activemodel/README
View
@@ -134,3 +134,11 @@ functionality from the following modules:
{Learn more}[link:classes/ActiveModel/Naming.html]
+* Adding observer support to your objects
+
+ ActiveModel::Observers allows your object to implement the Observer
+ pattern in a Rails App and take advantage of all the standard observer
+ functions.
+
+ {Learn more}[link:classes/ActiveModel/Observer.html]
+
21 activemodel/lib/active_model/observing.rb
View
@@ -24,8 +24,9 @@ module ClassMethods
# # Same as above, just using explicit class references
# ActiveRecord::Base.observers = Cacher, GarbageCollector
#
- # Note: Setting this does not instantiate the observers yet. +instantiate_observers+ is
- # called during startup, and before each development request.
+ # Note: Setting this does not instantiate the observers yet.
+ # +instantiate_observers+ is called during startup, and before
+ # each development request.
def observers=(*values)
@observers = values.flatten
end
@@ -102,10 +103,12 @@ def notify_observers(method)
#
# == Observing a class that can't be inferred
#
- # Observers will by default be mapped to the class with which they share a name. So CommentObserver will
- # be tied to observing Comment, ProductManagerObserver to ProductManager, and so on. If you want to name your observer
- # differently than the class you're interested in observing, you can use the Observer.observe class method which takes
- # either the concrete class (Product) or a symbol for that class (:product):
+ # Observers will by default be mapped to the class with which they share a
+ # name. So CommentObserver will be tied to observing Comment, ProductManagerObserver
+ # to ProductManager, and so on. If you want to name your observer differently than
+ # the class you're interested in observing, you can use the Observer.observe class
+ # method which takes either the concrete class (Product) or a symbol for that
+ # class (:product):
#
# class AuditObserver < ActiveModel::Observer
# observe :account
@@ -115,7 +118,8 @@ def notify_observers(method)
# end
# end
#
- # If the audit observer needs to watch more than one kind of object, this can be specified with multiple arguments:
+ # If the audit observer needs to watch more than one kind of object, this can be
+ # specified with multiple arguments:
#
# class AuditObserver < ActiveModel::Observer
# observe :account, :balance
@@ -125,7 +129,8 @@ def notify_observers(method)
# end
# end
#
- # The AuditObserver will now act on both updates to Account and Balance by treating them both as records.
+ # The AuditObserver will now act on both updates to Account and Balance by treating
+ # them both as records.
#
class Observer
include Singleton
Please sign in to comment.
Something went wrong with that request. Please try again.