This file contains 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
$redis.publish 'realtime_msg', { | |
msg: 'hello world - ' + SecureRandom.hex, | |
recipient_user_ids: [41, 42] | |
}.to_json |
This file contains 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
$redis.publish 'realtime_msg', { | |
channel: "/chats/#{@chat.id}", | |
event: 'chat', | |
message: { | |
html: @message, | |
sender: @member.username | |
} | |
}.to_json |
This file contains 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
socket.on('subscribe_public', function (m) { | |
socket.join(m.channel); | |
}); | |
socket.on('subscribe_private', function (m) { | |
if (m.jwt && is_valid_jwt(m.jwt)) { | |
socket.join(m.channel); | |
} | |
}); |
This file contains 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
// From client side, they just need to subscribe to what they need. | |
window.realtime.socketIo.emit('subscribe_public', { | |
channel: ch | |
}); | |
// or the private one, | |
window.realtime.socketIo.emit('subscribe_private', { | |
channel: ch, | |
jwt: localStorage.jwt | |
}); |
This file contains 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
DatabaseCleaner.strategy = :truncation, {:only => %w[widgets dogs some_other_collection]} | |
# or | |
DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]} |
This file contains 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
Before do | |
# ... | |
# list of all collection | |
Chat.delete_all | |
end |
This file contains 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 OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
def self.provides_callback_for(provider) | |
class_eval %Q{ | |
def #{provider} | |
# NOTE: | |
# Extract Oauth logic to a new ruby class. | |
@user = FactoryMethod::User.create("#{provider}", env["omniauth.auth"], current_user) | |
if @user.persisted? |
This file contains 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
# factory_method/user.rb | |
module FactoryMethod | |
# [Role] Factory | |
class User | |
def self.create(type, data=nil, current_user=nil) | |
if type == 'normal' | |
# login normally | |
else |
This file contains 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 FactoryMethod | |
# [Role] Product | |
class FacebookUser | |
def initialize(identity, data) | |
@identity = identity | |
@data = data | |
end | |
def create | |
@user = User.where(email: @data.info.email) |
This file contains 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
def paid! | |
# ... | |
if self.status == Order::UNPAID | |
# sent email, change status, ... | |
elsif self.status == Order::PAID | |
# do nothing | |
end | |
# ... |
OlderNewer