1f52448253
- Add Mozo::Broadcaster::ActionCable as drop-in Faye replacement - Fix model_broadcast.rb: delegate to Mozo directly instead of ApplicationController.new (memory-unsafe anti-pattern) - Add Broadcastable concern for clean model-side broadcasting - ActionCable config: async adapter, cable.yml, WebSocket endpoint - MozoChannel with per-entity authorization (user/supplier/employee) - Connection auth via auth_token (matches existing auth pattern) - Mount /cable WebSocket in routes - Add broadcasting-migration.md with Faye→ActionCable guide
32 lines
970 B
Ruby
32 lines
970 B
Ruby
# frozen_string_literal: true
|
|
|
|
# Broadcast shim: provides broadcast_supplier / broadcast_user to all
|
|
# SimplyStored::Couch models without requiring ApplicationController.new.
|
|
#
|
|
# PREVIOUSLY (dangerous):
|
|
# ApplicationController.new.send(:broadcast_supplier, *args)
|
|
# → leaked controller instances, no request lifecycle
|
|
#
|
|
# NOW:
|
|
# Delegates directly to Mozo.broadcast_supplier / Mozo.broadcast_user
|
|
# which uses Mozo.broadcaster (configurable: Faye or ActionCable).
|
|
#
|
|
# MIGRATION PATH:
|
|
# Models should `include Broadcastable` directly instead of relying
|
|
# on this monkey-patch. Once all models include Broadcastable, this
|
|
# initializer can be removed.
|
|
#
|
|
require 'simply_stored/couch'
|
|
|
|
module ModelBroadcast
|
|
def broadcast_supplier(sid, event, data = {})
|
|
Mozo.broadcast_supplier(sid, event, data)
|
|
end
|
|
|
|
def broadcast_user(uid, event, data = {})
|
|
Mozo.broadcast_user(uid, event, data)
|
|
end
|
|
end
|
|
|
|
SimplyStored::Couch.send(:include, ModelBroadcast)
|