action_cable_notifications 0.1.14 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,59 +0,0 @@
1
- module ActionCableNotifications
2
- module Streams
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- attr_accessor :stream_notification_options
7
- # Actions to be done when the module is included
8
- end
9
-
10
- def get_initial_values
11
- transmit self.stream_notification_options[:model].notify_initial self.stream_notification_options[:broadcasting]
12
- end
13
-
14
- private
15
-
16
- def stream_notifications_for(model, options = {}, &block)
17
- # Default options
18
- options = {
19
- model: model,
20
- actions: [:create, :update, :destroy],
21
- broadcasting: model.model_name.collection,
22
- callback: nil,
23
- coder: nil,
24
- include_initial: false, # Send all records to the subscriber on connection
25
- params: params,
26
- scope: :all # Default collection scope
27
- }.merge(options)
28
-
29
- # Sets channel options
30
- self.stream_notification_options = options
31
-
32
- # Checks if model already includes notification callbacks
33
- if !model.respond_to? :ActionCableNotificationsOptions
34
- model.send('include', ActionCableNotifications::Callbacks)
35
- # Set specified options on model
36
- end
37
-
38
- # Sets broadcast options if they are not already present in the model
39
- if not model.ActionCableNotificationsOptions.key? options[:broadcasting]
40
- model.broadcast_notifications_from options[:broadcasting], options
41
- end
42
-
43
- # Start streaming
44
- stream_from(options[:broadcasting], options[:callback] || block, options.slice(:coder))
45
-
46
- # Transmit initial state if required
47
- if options[:include_initial]
48
- # XXX: Check if data should be transmitted
49
- get_initial_values
50
- end
51
-
52
- end
53
-
54
- def unsubscribed
55
- stop_all_streams
56
- end
57
-
58
- end
59
- end