--- !ruby/object:RI::ClassDescription 
attributes: []

class_methods: 
- !ruby/object:RI::MethodSummary 
  name: new
- !ruby/object:RI::MethodSummary 
  name: observe
- !ruby/object:RI::MethodSummary 
  name: observed_class
comment: 
- !ruby/struct:SM::Flow::P 
  body: "Observer classes respond to lifecycle callbacks to implement trigger-like behavior outside the original class. This is a great way to reduce the clutter that normally comes when the model class is burdened with functionality that doesn't pertain to the core responsibility of the class. Example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  class CommentObserver &lt; ActiveRecord::Observer\n    def after_save(comment)\n      Notifications.deliver_comment(&quot;admin@do.com&quot;, &quot;New comment was posted&quot;, comment)\n    end\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: This Observer sends an email when a Comment#save is finished.
- !ruby/struct:SM::Flow::VERB 
  body: "  class ContactObserver &lt; ActiveRecord::Observer\n    def after_create(contact)\n      contact.logger.info('New contact added!')\n    end\n\n    def after_destroy(contact)\n      contact.logger.warn(&quot;Contact with an id of #{contact.id} was destroyed!&quot;)\n    end\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: This Observer uses logger to log when specific callbacks are triggered.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Observing a class that can't be inferred
- !ruby/struct:SM::Flow::P 
  body: "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):"
- !ruby/struct:SM::Flow::VERB 
  body: "  class AuditObserver &lt; ActiveRecord::Observer\n    observe :account\n\n    def after_update(account)\n      AuditTrail.new(account, &quot;UPDATED&quot;)\n    end\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: "If the audit observer needs to watch more than one kind of object, this can be specified with multiple arguments:"
- !ruby/struct:SM::Flow::VERB 
  body: "  class AuditObserver &lt; ActiveRecord::Observer\n    observe :account, :balance\n\n    def after_update(record)\n      AuditTrail.new(record, &quot;UPDATED&quot;)\n    end\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: The AuditObserver will now act on both updates to Account and Balance by treating them both as records.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Available callback methods
- !ruby/struct:SM::Flow::P 
  body: The observer can implement callback methods for each of the methods described in the Callbacks module.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Storing Observers in Rails
- !ruby/struct:SM::Flow::P 
  body: If you're using Active Record within Rails, observer classes are usually stored in app/models with the naming convention of app/models/audit_observer.rb.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Configuration
- !ruby/struct:SM::Flow::P 
  body: In order to activate an observer, list it in the <tt>config.active_record.observers</tt> configuration setting in your <tt>config/environment.rb</tt> file.
- !ruby/struct:SM::Flow::VERB 
  body: "  config.active_record.observers = :comment_observer, :signup_observer\n"
- !ruby/struct:SM::Flow::P 
  body: Observers will not be invoked unless you define these in your application configuration.
constants: []

full_name: ActiveRecord::Observer
includes: 
- !ruby/object:RI::IncludedModule 
  name: Singleton
instance_methods: 
- !ruby/object:RI::MethodSummary 
  name: add_observer!
- !ruby/object:RI::MethodSummary 
  name: observed_classes
- !ruby/object:RI::MethodSummary 
  name: observed_subclasses
name: Observer
superclass: Object
