Last active
July 16, 2017 16:54
-
-
Save yuemori/fa2067a175c7389436cf0e32b24a93e6 to your computer and use it in GitHub Desktop.
pubsub
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
| class User < ActiveRecord | |
| include Pubsub::Publisher | |
| after_create do | |
| publish(:welcome, user_name: name) | |
| end | |
| end | |
| class Post < ApplicationRecord | |
| include Pubsub::Publisher | |
| belongs_to :user | |
| after_create do | |
| publish(:create_post, user_name: user.name, title: title, image_url: user.image_url) | |
| end | |
| end | |
| class SlackNotifier | |
| include Pubsub::Subscriber | |
| use :slack, channel: '#general', username: 'angel', icon_emoji: ':innocent:' | |
| subscribe :User, :Post | |
| def welcome(context) | |
| notify_success("#{context[:user_name]} has joined.") | |
| end | |
| def create_post(context) | |
| notify_info("#{context[:user_name]} has create post of #{context[:title]}.", icon_url: context[:image_url]) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment