msgthr 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/GNUmakefile +1 -1
- data/lib/msgthr.rb +17 -2
- data/msgthr.gemspec +1 -1
- data/test/test_msgthr.rb +50 -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: 56db4fab8d4e41d33e1ed27c204951ef6cecda14043fcb63d6e6b801d587935d
|
4
|
+
data.tar.gz: e221116c16f9eb8afbfaaa2e1e6f6e8217216f27f5ec9440d7a65e99221960ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27c95fed5bfedc2bbc14cb19c2e42254337fb491730dfad26f4d59f7e6d9c5a7e90d81c1d0414ad746b7b8ad8267b061aef3f67740cf206e1aa8a8df4877954d
|
7
|
+
data.tar.gz: ad141c93c430a0600ff00b7c504a3237682858abd4238b8820830348f54527674d662e81445470821b4c68cbeba4ffdc51a6b149cc8e0a1a720a1981337b1990
|
data/GNUmakefile
CHANGED
data/lib/msgthr.rb
CHANGED
@@ -148,7 +148,18 @@ class Msgthr
|
|
148
148
|
# If +mid+ is a String, it is recommended to freeze the string before
|
149
149
|
# calling this method to avoid wasting memory on hash keys. Likewise
|
150
150
|
# is true for any String objects in +refs+.
|
151
|
-
|
151
|
+
#
|
152
|
+
# Adding a message could link 2 messages in Msgthr,
|
153
|
+
# by making one message a child of the other.
|
154
|
+
# It's possible to have a callback called when a child is added
|
155
|
+
# by passing a block to this method.
|
156
|
+
# This block can access the child and parent messages. E.g.
|
157
|
+
#
|
158
|
+
# msgthr.add(0, nil, '0')
|
159
|
+
# msgthr.add(1, [0], '1') do |parent, child|
|
160
|
+
# puts "#{parent.mid} -> #{child.mid}"
|
161
|
+
# end
|
162
|
+
def add(mid, refs, msg) # :yields: parent, child
|
152
163
|
@state == :init or raise StateError, "cannot add when already #@state"
|
153
164
|
|
154
165
|
cur = @id_table[mid] ||= Msgthr::Container.new(mid)
|
@@ -166,12 +177,16 @@ class Msgthr
|
|
166
177
|
# but do not change existing links or loop
|
167
178
|
if prev && !cont.parent && !cont.has_descendent(prev)
|
168
179
|
prev.add_child(cont)
|
180
|
+
yield(prev, cont) if block_given?
|
169
181
|
end
|
170
182
|
prev = cont
|
171
183
|
end
|
172
184
|
|
173
185
|
# set parent of this message to be the last element in refs
|
174
|
-
|
186
|
+
if prev
|
187
|
+
prev.add_child(cur)
|
188
|
+
yield(prev, cur) if block_given?
|
189
|
+
end
|
175
190
|
end
|
176
191
|
end
|
177
192
|
|
data/msgthr.gemspec
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
manifest = File.read('.manifest').split(/\n/)
|
6
6
|
s.name = %q{msgthr}
|
7
|
-
s.version = ENV['VERSION'] || '1.
|
7
|
+
s.version = ENV['VERSION'] || '1.2.0'
|
8
8
|
s.authors = ['msgthr hackers']
|
9
9
|
s.summary = 'container-agnostic, non-recursive message threading'
|
10
10
|
s.description = File.read('README').split(/\n\n/)[1].strip
|
data/test/test_msgthr.rb
CHANGED
@@ -6,8 +6,15 @@ require 'msgthr'
|
|
6
6
|
class TestMsgthr < Test::Unit::TestCase
|
7
7
|
def test_msgthr
|
8
8
|
thr = Msgthr.new
|
9
|
+
parent_child = ''
|
10
|
+
# Note that C is added after B,
|
11
|
+
# hence it's message will be empty after adding B
|
12
|
+
expected_parent_child = '->B'
|
9
13
|
thr.add('a', %w(c b), 'abc')
|
10
|
-
thr.add('b', %w(c), 'B')
|
14
|
+
thr.add('b', %w(c), 'B') do |parent, child|
|
15
|
+
parent_child = "#{parent.msg}->#{child.msg}"
|
16
|
+
end
|
17
|
+
assert_equal parent_child, expected_parent_child
|
11
18
|
thr.add('c', nil, 'c')
|
12
19
|
thr.add('D', nil, 'D')
|
13
20
|
thr.add('d', %w(missing), 'd')
|
@@ -95,4 +102,46 @@ EOF
|
|
95
102
|
EOF
|
96
103
|
assert_equal exp, out
|
97
104
|
end
|
105
|
+
|
106
|
+
def test_add_child_callback
|
107
|
+
thr = Msgthr.new
|
108
|
+
threads = {}
|
109
|
+
[1, 11, 12, 2, 21, 211].each{ |id| threads[id] = [id]}
|
110
|
+
my_add = lambda do |id, refs, msg|
|
111
|
+
thr.add(id, refs, msg) do |parent, child|
|
112
|
+
threads[child.mid] = threads[parent.mid]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
# Create the following structure
|
116
|
+
# 1
|
117
|
+
# \
|
118
|
+
# | 1.1
|
119
|
+
# \
|
120
|
+
# 1.2
|
121
|
+
# 2
|
122
|
+
# \
|
123
|
+
# 2.1
|
124
|
+
# \
|
125
|
+
# 2.1.1
|
126
|
+
my_add.call(1, nil, '1')
|
127
|
+
my_add.call(11, [1], '1.1')
|
128
|
+
my_add.call(12, [1], '1.2')
|
129
|
+
my_add.call(2, nil, '2')
|
130
|
+
my_add.call(21, [2], '2.1')
|
131
|
+
my_add.call(211, [21], '2.1.1')
|
132
|
+
|
133
|
+
thr.thread!
|
134
|
+
thr.rootset.each do |cnt|
|
135
|
+
threads[cnt.mid][0] = cnt.msg
|
136
|
+
end
|
137
|
+
|
138
|
+
assert_equal threads[1], threads[11]
|
139
|
+
assert_equal threads[1], threads[12]
|
140
|
+
assert_equal threads[2], threads[21]
|
141
|
+
assert_equal threads[2], threads[211]
|
142
|
+
assert_equal threads[21], threads[211]
|
143
|
+
assert_equal threads[1][0], '1'
|
144
|
+
assert_equal threads[2][0], '2'
|
145
|
+
end
|
146
|
+
|
98
147
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msgthr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- msgthr hackers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Pure Ruby message threading based on the algorithm described by
|