action_cable_notifications 0.1.30 → 0.1.35

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
- SHA1:
3
- metadata.gz: 64f6e0167fd97bc6b64dc43e1292c331cf7baff7
4
- data.tar.gz: bf24e8703a9953a7be75a3d80f73deb27a118508
2
+ SHA256:
3
+ metadata.gz: 791d0cda5f750319e778b0f7e0c9c656721d4ad4a3b2dcc6bf7377a88e7d10d8
4
+ data.tar.gz: '085b106ff16bde873da19f9c0d800cb5dfcdb184c4bf6607c60872d156fdf0a2'
5
5
  SHA512:
6
- metadata.gz: 624a3425d47cd3ea0291abdc706a7b3bc5c12c5d19715775012c364b70d4b00d30907399b3c161357012bca7b33ca4f9afd48ab6f09b4fd95f21c048444b8d1b
7
- data.tar.gz: 2848f179da19c2af48b313e07ae81638e481beac62cef85734d9c888e86c10622ffda3230bc2aa091f3589a9434624eebffd805a8d76a9fec6cbc5bfc7c7cb03
6
+ metadata.gz: 0d4270f9e8441719683eda7d7874b8f984c108999bcefa5ecf3df371a753c4172f53ea91ba441aa8147cf530126aeef5677d1168b675cd40a8e18e37ec1bcc66
7
+ data.tar.gz: 8f4c6acbecb415cd2e9f018ccc0fc17d1187a99ddd9cb77b00fe9aa5645378d693bda60a666707e21c5c6a3e538d5b4752d4f25df2f451b5663d7a5b07f13188
@@ -28,9 +28,6 @@ class CableNotifications.Collection
28
28
  # Cleanup performed commands
29
29
  _.remove(@commandsCache, {performed: true})
30
30
 
31
- # Clears the data array before fetching data
32
- @data.splice(0,@data.length)
33
-
34
31
  # Fetch data from upstream server when connection is resumed
35
32
  @fetch()
36
33
 
@@ -122,8 +119,8 @@ class CableNotifications.Collection
122
119
  @data.push (fields)
123
120
  @callbacks?.create?.call(this, fields)
124
121
  @callbacks?.changed?.call(this, @data) unless options.batching
125
-
126
- upstream.call(this, "create", {fields: fields})
122
+ else
123
+ upstream.call(this, "create", {fields: fields})
127
124
  fields
128
125
 
129
126
  # Update an existing record
@@ -139,8 +136,8 @@ class CableNotifications.Collection
139
136
  @callbacks?.update?.call(this, selector, fields, options)
140
137
  _.extend(record, fields)
141
138
  @callbacks?.changed?.call(this, @data) unless options.batching
142
-
143
- upstream.call(this, "update", {id: record.id, fields: fields})
139
+ else
140
+ upstream.call(this, "update", {id: record.id, fields: fields})
144
141
  record
145
142
 
146
143
  # Update an existing record or inserts a new one if there is no match
@@ -148,7 +145,7 @@ class CableNotifications.Collection
148
145
  @update(selector, fields, _.extend(options, {upsert: true}))
149
146
 
150
147
  # Destroy an existing record
151
- destroy: (selector={}) ->
148
+ destroy: (selector={}, options={}) ->
152
149
  index = _.findIndex(@data, selector)
153
150
  if index < 0
154
151
  console.warn("[destroy] Couldn't find a matching record:", selector)
@@ -158,6 +155,6 @@ class CableNotifications.Collection
158
155
  @data.splice(index, 1)
159
156
  @callbacks?.destroy?.call(this, selector)
160
157
  @callbacks?.changed?.call(this, @data) unless options.batching
161
-
162
- upstream.call(this, "destroy", {id: record.id})
158
+ else
159
+ upstream.call(this, "destroy", {id: record.id})
163
160
  record
@@ -13,11 +13,16 @@ module ActionCableNotifications
13
13
 
14
14
  # Get results using provided parameters and model configured scope
15
15
  begin
16
+ temp_scope = data[:model_options][:scope].deep_dup || {}
17
+ if (data[:model_options][:scope].is_a? Hash) && (data[:model_options][:scope][:where].is_a? Hash)
18
+ #temp_scope = temp_scope.merge(params)
19
+ temp_scope[:where].each{|k,v| v.is_a?(Proc) ? temp_scope[:where][k]=v.call() : nil }
20
+ end
16
21
  results = data[:model].
17
22
  select(params[:select] || []).
18
23
  limit(params[:limit]).
19
24
  where(params[:where] || {}).
20
- scoped_collection(data[:model_options][:scope]).
25
+ scoped_collection(temp_scope).
21
26
  to_a() rescue []
22
27
 
23
28
  response = {
@@ -13,6 +13,16 @@ module ActionCableNotifications
13
13
  after_create :notify_create
14
14
  after_destroy :notify_destroy
15
15
 
16
+ def record_within_scope records
17
+ if records.respond_to?(:where)
18
+ found_record = records.where(id: self.id).first
19
+ elsif records.respond_to?(:detect) and (found_record = records.detect{|e| e["id"]==self.id})
20
+ found_record
21
+ else
22
+ nil
23
+ end
24
+ end
25
+
16
26
  end
17
27
 
18
28
  class_methods do
@@ -74,8 +84,10 @@ module ActionCableNotifications
74
84
  def notify_create
75
85
  self.ChannelPublications.each do |publication, options|
76
86
  if options[:actions].include? :create
77
- # Checks if record is within scope before broadcasting
78
- if options[:scope]==:all or self.class.scoped_collection(options[:scope]).where(id: self.id).present?
87
+ # Checks if records is within scope before broadcasting
88
+ records = self.class.scoped_collection(options[:scope])
89
+
90
+ if options[:scope]==:all or record_within_scope(records)
79
91
  ActionCable.server.broadcast publication,
80
92
  msg: 'create',
81
93
  id: self.id,
@@ -91,9 +103,9 @@ module ActionCableNotifications
91
103
  if options[:scope]==:all
92
104
  options[:records].push self
93
105
  else
94
- record = self.class.scoped_collection(options[:scope]).where(id: self.id)
106
+ record = record_within_scope(self.class.scoped_collection(options[:scope]))
95
107
  if record.present?
96
- options[:records].push record.first
108
+ options[:records].push record
97
109
  end
98
110
  end
99
111
  end
@@ -117,8 +129,9 @@ module ActionCableNotifications
117
129
  self.ChannelPublications.each do |publication, options|
118
130
  if options[:actions].include? :update
119
131
  # Checks if previous record was within scope
120
- record = options[:records].detect{|r| r.id==self.id}
132
+ record = record_within_scope(options[:records])
121
133
  was_in_scope = record.present?
134
+
122
135
  options[:records].delete(record) if was_in_scope
123
136
 
124
137
  # Checks if current record is within scope
@@ -128,9 +141,8 @@ module ActionCableNotifications
128
141
  record = self
129
142
  is_in_scope = true
130
143
  else
131
- record = self.class.scoped_collection(options[:scope]).where(id: self.id)
144
+ record = record_within_scope(self.class.scoped_collection(options[:scope]))
132
145
  if record.present?
133
- record = record.first
134
146
  is_in_scope = true
135
147
  end
136
148
  end
@@ -173,7 +185,7 @@ module ActionCableNotifications
173
185
  self.ChannelPublications.each do |publication, options|
174
186
  if options[:scope]==:all or options[:actions].include? :destroy
175
187
  # Checks if record is within scope before broadcasting
176
- if options[:scope]==:all or self.class.scoped_collection(options[:scope]).where(id: self.id).present?
188
+ if options[:scope]==:all or record_within_scope(self.class.scoped_collection(options[:scope])).present?
177
189
  ActionCable.server.broadcast publication,
178
190
  msg: 'destroy',
179
191
  id: self.id
@@ -1,3 +1,3 @@
1
1
  module ActionCableNotifications
2
- VERSION = '0.1.30'
2
+ VERSION = '0.1.35'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_cable_notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.30
4
+ version: 0.1.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - ByS Sistemas de Control
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-19 00:00:00.000000000 Z
11
+ date: 2022-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -149,8 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  - !ruby/object:Gem::Version
150
150
  version: '0'
151
151
  requirements: []
152
- rubyforge_project:
153
- rubygems_version: 2.5.1
152
+ rubygems_version: 3.0.8
154
153
  signing_key:
155
154
  specification_version: 4
156
155
  summary: Automatic realtime notification broadcast for ActiveRecord models changes