aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael de Silva <michael@mwdesilva.com>2012-04-13 01:24:43 +0300
committerMichael de Silva <michael@mwdesilva.com>2012-04-13 01:24:43 +0300
commitb744199cc23a40b48c78e2b4353250da8fb55450 (patch)
tree340e201b31af7f172c082d56ef0fd6385d3f43c2
parent32df31317397adb573766ae349a53d0cda362edc (diff)
downloadrails-b744199cc23a40b48c78e2b4353250da8fb55450.tar.gz
rails-b744199cc23a40b48c78e2b4353250da8fb55450.tar.bz2
rails-b744199cc23a40b48c78e2b4353250da8fb55450.zip
Add documentation to detail passing of an object as the second
parameter passed to the ActiveSupport::Notifications.subscribe method instead of a block Example code sample and output is provided as well.
-rw-r--r--activesupport/lib/active_support/notifications.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb
index 521245e195..6735c561d3 100644
--- a/activesupport/lib/active_support/notifications.rb
+++ b/activesupport/lib/active_support/notifications.rb
@@ -57,6 +57,33 @@ module ActiveSupport
# is able to take the arguments as they come and provide an object-oriented
# interface to that data.
#
+ # It is also possible to pass an object as the second parameter passed to the
+ # <tt>subscribe</tt> method instead of a block:
+ #
+ # module ActionController
+ # class PageRequest
+ # def call(name, started, finished, unique_id, payload)
+ # Rails.logger.debug ["notification:", name, started, finished, unique_id, payload].join(" ")
+ # end
+ # end
+ # end
+ #
+ # ActiveSupport::Notifications.subscribe('process_action.action_controller', ActionController::PageRequest.new)
+ #
+ # resulting in the following output within the logs including a hash with the payload:
+ #
+ # notification: process_action.action_controller 2012-04-13 01:08:35 +0300 2012-04-13 01:08:35 +0300 af358ed7fab884532ec7 {
+ # :controller=>"Devise::SessionsController",
+ # :action=>"new",
+ # :params=>{"action"=>"new", "controller"=>"devise/sessions"},
+ # :format=>:html,
+ # :method=>"GET",
+ # :path=>"/login/sign_in",
+ # :status=>200,
+ # :view_runtime=>279.3080806732178,
+ # :db_runtime=>40.053
+ # }
+ #
# You can also subscribe to all events whose name matches a certain regexp:
#
# ActiveSupport::Notifications.subscribe(/render/) do |*args|