Sha256: 5d238a7be5834305cba0f1c6195375305cb661f0f5a8dfc6a2d9435787f89753
Contents?: true
Size: 1.16 KB
Versions: 4
Compression:
Stored size: 1.16 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 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 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 private def add_operation(key, options) operations[key] << options end def reset @operations = Hash.new { |hash, operation| hash[operation] = [] } end end end
Version data entries
4 entries across 4 versions & 1 rubygems