Skip to content

Instantly share code, notes, and snippets.

@ka8725
Created September 4, 2014 22:01
Show Gist options
  • Save ka8725/24c49f9befdcf48150bb to your computer and use it in GitHub Desktop.
Save ka8725/24c49f9befdcf48150bb to your computer and use it in GitHub Desktop.
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