Skip to content

Instantly share code, notes, and snippets.

@yuemori
Last active July 16, 2017 16:54
Show Gist options
  • Select an option

  • Save yuemori/fa2067a175c7389436cf0e32b24a93e6 to your computer and use it in GitHub Desktop.

Select an option

Save yuemori/fa2067a175c7389436cf0e32b24a93e6 to your computer and use it in GitHub Desktop.
pubsub
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