Method: GraphQL::Subscriptions::ActionCableSubscriptions#initialize

Defined in:
lib/graphql/subscriptions/action_cable_subscriptions.rb

#initialize(serializer: Serialize, namespace: '', action_cable: ActionCable, action_cable_coder: ActiveSupport::JSON, **rest) ⇒ ActionCableSubscriptions

Returns a new instance of ActionCableSubscriptions.

Parameters:

  • serializer (<#dump(obj), #load(string)] Used for serializing messages before handing them to `.broadcast(msg)`) (defaults to: Serialize)

    erializer [<#dump(obj), #load(string)] Used for serializing messages before handing them to .broadcast(msg)

  • namespace (string) (defaults to: '')

    Used to namespace events and subscriptions (default: '')



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/graphql/subscriptions/action_cable_subscriptions.rb', line 91

def initialize(serializer: Serialize, namespace: '', action_cable: ActionCable, action_cable_coder: ActiveSupport::JSON, **rest)
  # A per-process map of subscriptions to deliver.
  # This is provided by Rails, so let's use it
  @subscriptions = Concurrent::Map.new
  @events = Concurrent::Map.new do |h, k|
    h.compute_if_absent(k) do
      Concurrent::Map.new do |h2, k2|
        h2.compute_if_absent(k2) { Concurrent::Array.new }
      end
    end
  end
  @action_cable = action_cable
  @action_cable_coder = action_cable_coder
  @serializer = serializer
  @serialize_with_context = case @serializer.method(:load).arity
  when 1
    false
  when 2
    true
  else
    raise ArgumentError, "#{@serializer} must respond to `.load` accepting one or two arguments"
  end
  @transmit_ns = namespace
  super
end