peplum 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/peplum/application/peers.rb +1 -0
- data/lib/peplum/application/services/shared_hash.rb +38 -3
- data/lib/peplum/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cbd03ad31260b2a970bf3b4d3955a9b5a3aa9f8b8bbbffe5b49c1b07fdca539
|
4
|
+
data.tar.gz: cb85849f3733ba341a32aaf2628a5216df125f0fe686b035765c8584e4ad8d51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24cc90e163171f3a1ce7622ffef358015a8e3cea47293be4f9be814589196057d1e44213c7c9a4d7b77e3fed5476cddc9f10d1edac3b2155b9cc339e94527dad
|
7
|
+
data.tar.gz: efd88627c08d5b5048dd0940366e54f48c20c170dbe22749719574b09626e326909cda7abf730d85e145cff5173403631e4061f32ba23227498c2fdfecd56ea7
|
@@ -4,8 +4,13 @@ module Services
|
|
4
4
|
|
5
5
|
class SharedHash
|
6
6
|
|
7
|
-
def initialize
|
7
|
+
def initialize(*)
|
8
|
+
super
|
9
|
+
|
8
10
|
@hash = {}
|
11
|
+
|
12
|
+
@on_set_cb = {}
|
13
|
+
@on_delete_cb = {}
|
9
14
|
end
|
10
15
|
|
11
16
|
def get( k )
|
@@ -16,10 +21,11 @@ class SharedHash
|
|
16
21
|
return if @hash[k] == v
|
17
22
|
|
18
23
|
@hash[k] = v
|
24
|
+
call_on_set( k, v )
|
19
25
|
|
20
26
|
if broadcast
|
21
27
|
each_peer do |peer|
|
22
|
-
peer.
|
28
|
+
peer.send( name ).set( k, v, false )
|
23
29
|
end
|
24
30
|
end
|
25
31
|
|
@@ -30,22 +36,51 @@ class SharedHash
|
|
30
36
|
return if !@hash.include? k
|
31
37
|
|
32
38
|
@hash.delete( k )
|
39
|
+
call_on_delete( k )
|
33
40
|
|
34
41
|
if broadcast
|
35
42
|
each_peer do |_, peer|
|
36
|
-
peer.
|
43
|
+
peer.send( name ).delete( k, false )
|
37
44
|
end
|
38
45
|
end
|
39
46
|
|
40
47
|
nil
|
41
48
|
end
|
42
49
|
|
50
|
+
def on_set( k, &block )
|
51
|
+
(@on_set_cb[k] ||= []) << block
|
52
|
+
end
|
53
|
+
|
54
|
+
def on_delete( k, &block )
|
55
|
+
(@on_delete_cb ||= []) << block
|
56
|
+
end
|
57
|
+
|
43
58
|
def to_h
|
44
59
|
@hash.dup
|
45
60
|
end
|
46
61
|
|
47
62
|
private
|
48
63
|
|
64
|
+
def call_on_set( k, v )
|
65
|
+
return if !@on_set_cb[k]
|
66
|
+
|
67
|
+
@on_set_cb[k].each do |cb|
|
68
|
+
cb.call v
|
69
|
+
end
|
70
|
+
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def call_on_delete( k )
|
75
|
+
return if !@on_delete_cb[k]
|
76
|
+
|
77
|
+
@on_delete_cb[k].each do |cb|
|
78
|
+
cb.call
|
79
|
+
end
|
80
|
+
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
|
49
84
|
def each_peer( &block )
|
50
85
|
Cuboid::Application.application.peers.each( &block )
|
51
86
|
end
|
data/lib/peplum/version.rb
CHANGED