Class: ApiMaker::SubscriptionsChannel

Inherits:
ApplicationCable::Channel
  • Object
show all
Defined in:
app/channels/api_maker/subscriptions_channel.rb

Instance Method Summary collapse

Instance Method Details

#subscribedObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/channels/api_maker/subscriptions_channel.rb', line 2

def subscribed
  params[:subscription_data].each do |model_name, subscription_types|
    subscription_types["model_class_events"]&.each do |event_name|
      connect_model_class_event(model_name, event_name)
    end

    subscription_types["events"]&.each do |event_name, model_ids|
      connect_event(model_name, model_ids, event_name)
    end

    connect_creates(model_name) if subscription_types.key?("creates")

    if subscription_types.key?("updates")
      model_ids = subscription_types.fetch("updates")
      connect_updates(model_name, model_ids)
    end

    if subscription_types.key?("destroys")
      model_ids = subscription_types.fetch("destroys")
      connect_destroys(model_name, model_ids)
    end
  end
end