Sha256: 2a63392ce12e7828eed9ad33c072bbc8d1037602bea17611812486739f5cb9b0
Contents?: true
Size: 932 Bytes
Versions: 25
Compression:
Stored size: 932 Bytes
Contents
module ForeignOffice module Broadcaster def self.included(base) base.extend ClassMethods def handle_broadcast self.broadcast_change if self.changed? end def broadcast_change Rails.logger.debug "Broadcasting change for #{self.inspect}..." Rails.logger.debug "Class name: #{self.class.name}" Rails.logger.debug "ID: #{self.id}" Rails.logger.debug "Serialize: #{self.serialize}" ForeignOffice.publish(channel: "#{self.class.name}#{self.id}", object: self.serialize) rescue => e Rails.logger.error "Failed to broadcast change: #{e.inspect}" Rails.logger.debug e.backtrace.join("\n") raise e end def serialize self.attributes end end module ClassMethods def broadcast_changes! self.send(:after_save, :handle_broadcast, {unless: :skip_all_callbacks}) end end end end
Version data entries
25 entries across 25 versions & 1 rubygems