pinkman 0.9.9.9.10 → 0.9.9.9.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/pinkman_base/collection.coffee +16 -4
- data/app/assets/javascripts/pinkman_base/controller.coffee +6 -1
- data/app/assets/javascripts/pinkman_base/object.coffee.erb +23 -1
- data/app/channels/pinkman_channel.rb +1 -1
- data/lib/generators/pinkman/templates/channel.rb.erb +3 -3
- data/lib/pinkman/broadcaster.rb +8 -7
- data/lib/pinkman/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 542f0294f57dc31831c1f3edf26e84eff18a8b52c12dc590a5829e4e32947ad5
|
4
|
+
data.tar.gz: bd5f4831742985e4f214d7a67d4863297cacf8ec9065f8254e0e3e3d1acc0863
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f008682f5279f37b1dfc5007cf5bf185c9dc9cac65226ac709cfd506a93e291b5a3fcd6f4c107b321a87662e38d3d33a2e5deb2d07325e0854de3b76ebf779f1
|
7
|
+
data.tar.gz: 12d8a131e75349686ef9168c6290f51c22684c3900d17ce82aa06c3c605eaca36aae37d18ea2ba74f1c9be19b21eae09d07a9af521362b2f3367ac3941f07f29
|
@@ -212,13 +212,25 @@ class window.PinkmanCollection extends window.PinkmanCommon
|
|
212
212
|
shift: ->
|
213
213
|
@remove(@first())
|
214
214
|
|
215
|
+
removeId: (id,callback) ->
|
216
|
+
@find id, (obj) =>
|
217
|
+
if obj?
|
218
|
+
i = @collection.indexOf(obj)
|
219
|
+
@collection.splice(i,1)
|
220
|
+
callback(this) if $p.isFunction(callback)
|
221
|
+
|
215
222
|
# Desc: remove a object from the collection
|
216
223
|
remove: (object,callback) ->
|
217
|
-
if typeof object == 'object' and object.id?
|
218
|
-
|
219
|
-
@
|
220
|
-
|
224
|
+
if typeof object == 'object' and object.id?
|
225
|
+
# console.log 'id'
|
226
|
+
if (@any (o) -> o.id == object.id)
|
227
|
+
# console.log 'any'
|
228
|
+
value = @find(object.id)
|
229
|
+
# console.log value
|
230
|
+
i = @collection.indexOf(value)
|
231
|
+
@collection.splice(i,1)
|
221
232
|
else
|
233
|
+
console.log 'js'
|
222
234
|
i = @collection.indexOf object
|
223
235
|
@collection.splice(i,1)
|
224
236
|
value = object
|
@@ -289,10 +289,15 @@ class window.PinkmanController extends window.PinkmanObject
|
|
289
289
|
callback = if typeof opt == 'function' then opt else opt['callback']
|
290
290
|
catch
|
291
291
|
throw 'Callback not found.'
|
292
|
+
throw 'Subscriber: blank options param' unless opt
|
293
|
+
throw 'Subscriber: options not a object' unless $p.isObject(opt)
|
294
|
+
throw 'Subscriber: options missing room value' unless opt.room?
|
295
|
+
throw 'Subscriber: options missing scope value' unless opt.scope?
|
292
296
|
params = if (typeof opt == 'object' and opt['params']?) then opt['params'] else new Object
|
293
297
|
params.channel = channel
|
294
298
|
if $p.isObject(opt)
|
295
|
-
params.room = opt.room
|
299
|
+
params.room = opt.room
|
300
|
+
params.scope = opt.scope
|
296
301
|
params.filter_by = (opt.filter_by or opt.filterBy ) if (opt.filterBy? or opt.filter_by?)
|
297
302
|
Pinkman.cable.subscriptions.create params, received: callback
|
298
303
|
|
@@ -7,7 +7,25 @@ class window.PinkmanObject extends window.PinkmanCommon
|
|
7
7
|
@isObject = true
|
8
8
|
@pinkmanType = 'object'
|
9
9
|
@collections = new PinkmanCollection
|
10
|
+
if $p.isArray(@constructor.instances)
|
11
|
+
@constructor.instances.push(this)
|
12
|
+
else
|
13
|
+
@constructor.instances = [this]
|
10
14
|
Pinkman.objects.push(this)
|
15
|
+
|
16
|
+
@sync: (obj,callback,each) ->
|
17
|
+
if $p.isArray(@instances) and $p.isObject(obj) and obj.id?
|
18
|
+
length = @instances.length
|
19
|
+
i = 0
|
20
|
+
for instance in @instances
|
21
|
+
i = i + 1
|
22
|
+
if instance.id? and instance.id == obj.id
|
23
|
+
if obj.isPink then instance.assign(obj.attributes()) else instance.assign(obj)
|
24
|
+
each(instance) if $p.isFunction(each) and obj.pinkey != instance.pinkey
|
25
|
+
callback() if (length == i) and $p.isFunction(callback)
|
26
|
+
|
27
|
+
else
|
28
|
+
true
|
11
29
|
|
12
30
|
# Desc: assign attributes from a pure javascript object
|
13
31
|
# Usage: a.assign( {attribute: value} )
|
@@ -97,7 +115,9 @@ class window.PinkmanObject extends window.PinkmanCommon
|
|
97
115
|
|
98
116
|
# Desc: remove this object from all collections
|
99
117
|
clearCollections: ->
|
100
|
-
|
118
|
+
@collections.each (c) =>
|
119
|
+
# console.log this
|
120
|
+
c.removeId(@id) if @id?
|
101
121
|
|
102
122
|
# alias for clearCollections
|
103
123
|
removeFromCollections: ->
|
@@ -184,6 +204,7 @@ class window.PinkmanObject extends window.PinkmanCommon
|
|
184
204
|
save: (callback='') ->
|
185
205
|
if @id? and @id!='' then @update(callback) else @create(callback)
|
186
206
|
|
207
|
+
# delete and remove from collections
|
187
208
|
destroy: (callback='') ->
|
188
209
|
if @id?
|
189
210
|
@removeFromAllCollections()
|
@@ -199,6 +220,7 @@ class window.PinkmanObject extends window.PinkmanCommon
|
|
199
220
|
else
|
200
221
|
return(false)
|
201
222
|
|
223
|
+
# delete and dont touch collections
|
202
224
|
delete: (callback='') ->
|
203
225
|
if @id?
|
204
226
|
Pinkman.ajax.delete
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class <%= channel_name %> < PinkmanChannel
|
2
2
|
|
3
|
-
# TO DO: use connection/params
|
4
|
-
def
|
5
|
-
:public
|
3
|
+
# TO DO: use connection/params and return an array of scopes (symbols) the current user can subscribe
|
4
|
+
def current_allowed_scopes
|
5
|
+
[:public]
|
6
6
|
end
|
7
7
|
|
8
8
|
# broadcast :public do |config|
|
data/lib/pinkman/broadcaster.rb
CHANGED
@@ -22,24 +22,25 @@ class Pinkman::Broadcaster
|
|
22
22
|
ActionCable.server.broadcast(room_name_from_record(room,record), {action: action, data: record.json_hash(scope)})
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.stream channel,
|
26
|
-
if params[:room].present?
|
25
|
+
def self.stream channel, current_allowed_scopes, params
|
26
|
+
if params[:room].present? and params[:scope].present?
|
27
27
|
broadcaster = broadcasters[params[:room].to_sym]
|
28
|
-
|
28
|
+
raise 'Unknown scope' unless params[:scope].is_a?(String)
|
29
|
+
if broadcaster.present? and params[:scope].to_sym.in?(current_allowed_scopes)
|
29
30
|
channel.stream_from(room_name_from_params(broadcaster,params))
|
30
31
|
else
|
31
32
|
raise "Insuficient permissions or room '#{params[:room]}' not found."
|
32
33
|
end
|
33
34
|
else
|
34
|
-
raise 'Room not specified through client.'
|
35
|
+
raise 'Room or Scope not specified through client.'
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
39
|
def self.room_name_from_params broadcaster, params
|
39
|
-
if params[:filter_by].is_a?
|
40
|
-
broadcaster.encrypt(broadcaster.room,params[:filter_by])
|
40
|
+
if params[:filter_by].is_a?(String) or params[:filter_by].is_a?(Numeric)
|
41
|
+
broadcaster.encrypt(broadcaster.room,params[:filter_by].to_s)
|
41
42
|
elsif params[:filter_by].is_a? Array
|
42
|
-
broadcaster.encrypt(broadcaster.room, params[:filter_by].join(' '))
|
43
|
+
broadcaster.encrypt(broadcaster.room, params[:filter_by].map(&:to_s).join(' '))
|
43
44
|
else
|
44
45
|
broadcaster.room
|
45
46
|
end
|
data/lib/pinkman/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pinkman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.9.9.
|
4
|
+
version: 0.9.9.9.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Agilso Oliveira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|