peplum 0.2.2 → 0.2.3
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 +33 -0
- 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: 39020843c5d8edc0d848f1b08bc88fdc73aed389241a757f3b8f55cd1b5a151e
|
4
|
+
data.tar.gz: c3a31f27cdd3e95f840cfd0466d6facdf596f8dc306a1063091f5862b19f2ae6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95a6bdcd3f8ce0b86dba303250304e79c3455bbd7f63dc05e226ff5605c7769ce396b7b70f4a0a53144cc0cc0767a70653a0123deac6d756b9b6ab8823489ceb
|
7
|
+
data.tar.gz: '0806c44ba530ff2cd8e5ec6cc0e53acdd4519a00c5c5b0e5d6514be173f522c2e01fa137ae97fe411ad3d9698d0db2901f3775b98f96e8fb7c9843d31f5ac2f6'
|
@@ -6,6 +6,9 @@ class SharedHash
|
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@hash = {}
|
9
|
+
|
10
|
+
@on_set_cb = {}
|
11
|
+
@on_delete_cb = {}
|
9
12
|
end
|
10
13
|
|
11
14
|
def get( k )
|
@@ -16,6 +19,7 @@ class SharedHash
|
|
16
19
|
return if @hash[k] == v
|
17
20
|
|
18
21
|
@hash[k] = v
|
22
|
+
call_on_set( k, v )
|
19
23
|
|
20
24
|
if broadcast
|
21
25
|
each_peer do |peer|
|
@@ -30,6 +34,7 @@ class SharedHash
|
|
30
34
|
return if !@hash.include? k
|
31
35
|
|
32
36
|
@hash.delete( k )
|
37
|
+
call_on_delete( k )
|
33
38
|
|
34
39
|
if broadcast
|
35
40
|
each_peer do |_, peer|
|
@@ -40,12 +45,40 @@ class SharedHash
|
|
40
45
|
nil
|
41
46
|
end
|
42
47
|
|
48
|
+
def on_set( k, &block )
|
49
|
+
(@on_set_cb[k] ||= []) << block
|
50
|
+
end
|
51
|
+
|
52
|
+
def on_delete( k, &block )
|
53
|
+
(@on_delete_cb ||= []) << block
|
54
|
+
end
|
55
|
+
|
43
56
|
def to_h
|
44
57
|
@hash.dup
|
45
58
|
end
|
46
59
|
|
47
60
|
private
|
48
61
|
|
62
|
+
def call_on_set( k, v )
|
63
|
+
return if !@on_set_cb[k]
|
64
|
+
|
65
|
+
@on_set_cb[k].each do |cb|
|
66
|
+
cb.call v
|
67
|
+
end
|
68
|
+
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
|
72
|
+
def call_on_delete( k )
|
73
|
+
return if !@on_delete_cb[k]
|
74
|
+
|
75
|
+
@on_delete_cb[k].each do |cb|
|
76
|
+
cb.call
|
77
|
+
end
|
78
|
+
|
79
|
+
nil
|
80
|
+
end
|
81
|
+
|
49
82
|
def each_peer( &block )
|
50
83
|
Cuboid::Application.application.peers.each( &block )
|
51
84
|
end
|
data/lib/peplum/version.rb
CHANGED