Last active
August 29, 2015 14:10
-
-
Save costa/bf81827963b5f6987c4f to your computer and use it in GitHub Desktop.
Rails model notification concern employing Pusher: app/models/concerns
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 Notification | |
| extend ActiveSupport::Concern | |
| included do | |
| after_create { notify 'created' } | |
| after_update { notify 'updated' } | |
| after_destroy { notify 'destroyed' } | |
| class << self | |
| def notify_async(channel, event, json) | |
| Pusher[channel].trigger event, json | |
| end | |
| handle_asynchronously :notify_async, :priority => REALTIME_NOTIFICATIONS_PRIORITY | |
| end | |
| end | |
| private | |
| def notify(event) | |
| self.class.notify_async pusher_channel, event, as_json if pusher_channel | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment