Created
September 4, 2014 22:01
-
-
Save ka8725/24c49f9befdcf48150bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Publisher | |
extend self | |
# delegate to ActiveSupport::Notifications.instrument | |
def broadcast_event(event_name, payload={}) | |
if block_given? | |
ActiveSupport::Notifications.instrument(event_name, payload) do | |
yield | |
end | |
else | |
ActiveSupport::Notifications.instrument(event_name, payload) | |
end | |
end | |
end | |
module Subscriber | |
# delegate to ActiveSupport::Notifications.subscribe | |
def self.subscribe(event_name) | |
if block_given? | |
ActiveSupport::Notifications.subscribe(event_name) do |*args| | |
event = ActiveSupport::Notifications::Event.new(*args) | |
yield(event) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment