action_cable_notifications 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3208ee7a8df2cd087f3ef9067fca4da783ef9afe
4
- data.tar.gz: 15d6a3138c7d6aa2b4b2cebdd1b54673ac51616c
3
+ metadata.gz: 79722760dc7087e962c3dae93d08d9680d472472
4
+ data.tar.gz: 39dfd3ec02a502ec8005fe3eb723275bde0ccd46
5
5
  SHA512:
6
- metadata.gz: 2ecb8ca921ea58baddd3452a51aa3243fdfb8c20ecf3760f5a9c003ab9f782bf335240d0c89a464894e0f540f83b89eaeedd91a848065167ede83acbdd0cfdda
7
- data.tar.gz: a02c1d61f271a7f1402f21e24bd8ac45893df76ca944d17ef4ca733b22ab0ce944a1ea652e9569691450d9b02d6d370259ee15fd13ee7eb45a89286312c1aaa8
6
+ metadata.gz: 8e3edd413a94cd4104ebf0499877b7c66cdf2be8d191b3cd66a08de8282ecaf0d3e47bc60ac7ddd16399137f596c4024ffc04cb4eb5ac23cfb57670f4eaa9014
7
+ data.tar.gz: c975d1f2af7e6b0f869f6252468fc8204cf1f61be7ae05c247d50a3452ee7969dabee84b2d721ab82c80c324e51b44cc247d3fc671a4cc8ed5526eae832a87e7
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # ActionCableNotifications
2
- Short description and motivation.
2
+ [![Gem Version](https://badge.fury.io/rb/action_cable_notifications.svg)](https://badge.fury.io/rb/action_cable_notifications)
3
+
4
+ This gem is under develoment and is not ready for production usage.
3
5
 
4
6
  ## Usage
5
7
  How to use my plugin.
@@ -30,7 +32,7 @@ class TestChannel < ApplicationCable::Channel
30
32
  include ActionCableNotifications::Streams
31
33
 
32
34
  def subscribed
33
- stream_for model, include_initial: true
35
+ stream_notifications_for model, include_initial: true
34
36
  end
35
37
 
36
38
  def unsubscribed
@@ -3,24 +3,31 @@ module ActionCableNotifications
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
+ # Options
7
+ class_attribute :ActionCableNotificationsOptions
8
+ self.ActionCableNotificationsOptions = {}
9
+
6
10
  after_update :notify_update
7
11
  after_create :notify_create
8
12
  after_destroy :notify_destroy
9
13
  end
10
14
 
11
15
  module ClassMethods
12
- def notify_initial( collection=nil )
13
- collection ||= self
16
+ def set_action_cable_notification_options( options = {} )
17
+ self.ActionCableNotificationsOptions = options
18
+ end
19
+
20
+ def notify_initial
14
21
  data = {
15
22
  collection: self.model_name.collection,
16
23
  msg: 'add',
17
- data: collection.all
24
+ data: self.all
18
25
  }
19
26
  end
20
27
  end
21
28
 
22
29
  def notify_create
23
- ActionCable.server.broadcast self.model_name.collection,
30
+ ActionCable.server.broadcast self.ActionCableNotificationsOptions[:broadcast_name],
24
31
  collection: self.model_name.collection,
25
32
  msg: 'create',
26
33
  id: self.id,
@@ -33,7 +40,7 @@ module ActionCableNotifications
33
40
  changes[k] = v[1]
34
41
  end
35
42
 
36
- ActionCable.server.broadcast self.model_name.collection,
43
+ ActionCable.server.broadcast self.ActionCableNotificationsOptions[:broadcast_name],
37
44
  collection: self.model_name.collection,
38
45
  msg: 'update',
39
46
  id: self.id,
@@ -41,7 +48,7 @@ module ActionCableNotifications
41
48
  end
42
49
 
43
50
  def notify_destroy
44
- ActionCable.server.broadcast self.model_name.collection,
51
+ ActionCable.server.broadcast self.ActionCableNotificationsOptions[:broadcast_name],
45
52
  collection: self.model_name.collection,
46
53
  msg: 'destroy',
47
54
  id: self.id
@@ -3,31 +3,33 @@ module ActionCableNotifications
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- class_attribute :ActionCableNotificationsOptions
7
- self.ActionCableNotificationsOptions = {}
6
+
8
7
  end
9
8
 
10
9
  private
11
10
 
12
- def stream_for(model, options = {})
11
+ def stream_notifications_for(model, options = {}, callback = nil)
12
+ # Default options
13
+ options = {
14
+ include_initial: false, # Send all records to the subscriber on connection
15
+ broadcast_name: model.model_name.collection
16
+ }.merge(options)
13
17
 
14
- # Original behaviour
15
- if options.is_a? Proc
16
- super(model, options)
17
- else
18
+ # Checks if model already includes notification callbacks
19
+ if !model.respond_to? :ActionCableNotificationsOptions
20
+ model.send('include', ActionCableNotifications::Callbacks)
21
+ end
18
22
 
19
- # Checks if model already includes notification callbacks
20
- if !model.respond_to? :notify_initial
21
- model.send('include', ActionCableNotifications::Callbacks)
22
- end
23
+ # Set specified options on model
24
+ model.send('set_action_cable_notification_options', options)
23
25
 
24
- super(model, options[:callback])
26
+ stream_from(options[:broadcast_name], callback)
25
27
 
26
- # Transmit initial state if required
27
- if options[:include_initial].present?
28
- transmit model.notify_initial
29
- end
28
+ # Transmit initial state if required
29
+ if options[:include_initial]
30
+ transmit model.notify_initial
30
31
  end
32
+
31
33
  end
32
34
 
33
35
  end
@@ -1,3 +1,3 @@
1
1
  module ActionCableNotifications
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_cable_notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ByS Sistemas de Control