Module: ActionCableNotifications::Channel

Extended by:
ActiveSupport::Concern
Includes:
Actions, Cache
Defined in:
lib/action_cable_notifications/channel.rb,
lib/action_cable_notifications/channel_cache.rb,
lib/action_cable_notifications/channel_actions.rb

Defined Under Namespace

Modules: Actions, Cache

Instance Method Summary collapse

Methods included from Cache

#update_cache

Methods included from Actions

#create, #destroy, #fetch, #update

Instance Method Details

#action(data) ⇒ Object

Process actions sent from the client

"collection": "model.model_name.collection"
"command": "fetch"
"params": {

}

Parameters:

  • data (Hash)

    Contains command to be executed and its parameters



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/action_cable_notifications/channel.rb', line 28

def action(data)
  data.deep_symbolize_keys!

  channel_options = self.ActionCableNotifications[data[:collection]]
  model = channel_options[:model]
  broadcasting = channel_options[:broadcasting]
  model_options = model.ActionCableNotificationsOptions[broadcasting]

  params = {
    model: model,
    model_options: model_options,
    params: data[:params]
  }

  case data[:command]
  when "fetch"
    fetch(params)
  when "create"
    create(params)
  when "update"
    update(params)
  when "destroy"
    destroy(params)
  end
end

#initialize(*args) ⇒ Object



54
55
56
57
# File 'lib/action_cable_notifications/channel.rb', line 54

def initialize(*args)
  super
  @collections = {}
end

#subscribedObject



59
60
61
62
# File 'lib/action_cable_notifications/channel.rb', line 59

def subscribed
  # XXX Check if this is new connection or a reconection of a
  # previously active client
end

#unsubscribedObject



64
65
66
# File 'lib/action_cable_notifications/channel.rb', line 64

def unsubscribed
  stop_all_streams
end