loco-rails 4.0.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Loco
4
- class UuidJob < ActiveJob::Base
5
- queue_as :loco
6
-
7
- def perform(serialized_resource, uuid, action)
8
- ws_conn_manager = init_ws_conn_manager serialized_resource
9
- return unless ws_conn_manager
10
-
11
- case action
12
- when 'add'
13
- add ws_conn_manager, uuid
14
- when 'del'
15
- del ws_conn_manager, uuid
16
- when 'update'
17
- update ws_conn_manager, uuid
18
- end
19
- end
20
-
21
- protected
22
-
23
- def add(ws_conn_manager, uuid)
24
- ws_conn_manager.add uuid
25
- WsConnectedResourcesManager.add ws_conn_manager.identifier
26
- end
27
-
28
- def del(ws_conn_manager, uuid)
29
- ws_conn_manager.del uuid
30
- return if ws_conn_manager.connected_uuids.any?
31
-
32
- WsConnectedResourcesManager.del ws_conn_manager.identifier
33
- end
34
-
35
- def update(ws_conn_manager, uuid)
36
- ws_conn_manager.update uuid
37
- WsConnectedResourcesManager.add ws_conn_manager.identifier
38
- end
39
-
40
- def deserialize_resource(hash)
41
- hash['class'].constantize.find_by id: hash['id']
42
- end
43
-
44
- def init_ws_conn_manager(serialized_resource)
45
- resource = deserialize_resource serialized_resource
46
- return unless resource
47
-
48
- WsConnectionManager.new resource
49
- end
50
- end
51
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Loco
4
- class WsConnectedResourcesManager
5
- def initialize(resources)
6
- @resources = resources
7
- @connected_resources = nil
8
- end
9
-
10
- class << self
11
- def identifiers
12
- val = WsConnectionStorage.current.get key
13
- return [] if val.blank?
14
-
15
- JSON.parse val
16
- end
17
-
18
- def add(identifier)
19
- ids = identifiers
20
- return if ids.include? identifier
21
-
22
- ids << identifier
23
- WsConnectionStorage.current.set key, ids.to_json
24
- end
25
-
26
- def del(identifier)
27
- ids = identifiers
28
- return unless ids.include? identifier
29
-
30
- ids.delete identifier
31
- WsConnectionStorage.current.set key, ids.to_json
32
- end
33
-
34
- def key
35
- 'loco:conn_ids'
36
- end
37
- end
38
-
39
- def connected_resources
40
- return @connected_resources if @connected_resources
41
-
42
- @resources.each do |resource|
43
- next if WsConnectionManager.new(resource).connected_uuids.empty?
44
-
45
- add resource
46
- end
47
- @connected_resources || []
48
- end
49
-
50
- def connected?(resource)
51
- connected_resources.map do |res|
52
- WsConnectionManager.new(res).identifier
53
- end.include? WsConnectionManager.new(resource).identifier
54
- end
55
-
56
- private
57
-
58
- def add(resource)
59
- @connected_resources ||= []
60
- @connected_resources << resource
61
- @connected_resources.uniq!
62
- end
63
- end
64
- end