Sha256: 0dac38d18b7838cd9eda11a96c3f4d17227f49ba669c5f470d701d6d6eeacc2b
Contents?: true
Size: 1.42 KB
Versions: 4
Compression:
Stored size: 1.42 KB
Contents
# frozen_string_literal: true module CableReady class Channel attr_reader :identifier, :operations, :available_operations def initialize(identifier, available_operations) @identifier = identifier @available_operations = available_operations reset available_operations.each do |available_operation, implementation| define_singleton_method available_operation, &implementation end end def channel_broadcast(clear) operations.select! { |_, list| list.present? } operations.deep_transform_keys! { |key| key.to_s.camelize(:lower) } ActionCable.server.broadcast identifier, {"cableReady" => true, "operations" => operations} reset if clear end def channel_broadcast_to(model, clear) operations.select! { |_, list| list.present? } operations.deep_transform_keys! { |key| key.to_s.camelize(:lower) } identifier.broadcast_to model, {"cableReady" => true, "operations" => operations} reset if clear end def broadcast(clear = true) CableReady::Channels.instance.broadcast(identifier, clear) end def broadcast_to(model, clear = true) CableReady::Channels.instance.broadcast_to(model, identifier, clear) end private def enqueue_operation(key, options) operations[key] << options self end def reset @operations = Hash.new { |hash, operation| hash[operation] = [] } end end end
Version data entries
4 entries across 4 versions & 1 rubygems