wref 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/wref.rb +26 -0
- data/spec/wref_spec.rb +34 -2
- data/wref.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/wref.rb
CHANGED
@@ -248,6 +248,32 @@ class Wref_map
|
|
248
248
|
end
|
249
249
|
end
|
250
250
|
|
251
|
+
#Iterates over every valid object in the weak map.
|
252
|
+
#===Examples
|
253
|
+
# map.each do |obj|
|
254
|
+
# puts "Object alive: #{obj}"
|
255
|
+
# end
|
256
|
+
def each(&block)
|
257
|
+
enum = Enumerator.new do |yielder|
|
258
|
+
ids = nil
|
259
|
+
@mutex.synchronize do
|
260
|
+
ids = @map.keys
|
261
|
+
end
|
262
|
+
|
263
|
+
ids.each do |id|
|
264
|
+
if obj = self.get!(id)
|
265
|
+
yielder << obj
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
if block
|
271
|
+
enum.each(&block)
|
272
|
+
else
|
273
|
+
return enum
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
251
277
|
#Make it hash-compatible.
|
252
278
|
alias has_key? key?
|
253
279
|
alias [] get
|
data/spec/wref_spec.rb
CHANGED
@@ -20,10 +20,42 @@ describe "Wref" do
|
|
20
20
|
str = "Test"
|
21
21
|
map = Wref_map.new
|
22
22
|
map[5] = str
|
23
|
+
map[6] = "trala"
|
24
|
+
|
23
25
|
raise "Should have been valid but wasnt." if !map.valid?(5)
|
24
26
|
str = nil
|
25
|
-
|
26
|
-
|
27
|
+
|
28
|
+
#Test each-method.
|
29
|
+
count = 0
|
30
|
+
str_col = ""
|
31
|
+
map.each do |a_str|
|
32
|
+
count += 1
|
33
|
+
str_col << a_str
|
34
|
+
end
|
35
|
+
|
36
|
+
raise "Expected collection to be 'Testtrala' but it wasnt: #{str_col}" if str_col != "Testtrala"
|
37
|
+
raise "Expected count 2 but it wasnt: #{count}" if count != 2
|
38
|
+
|
39
|
+
#Make the engine work a little to force garbage collection.
|
40
|
+
0.upto(10) do
|
41
|
+
str = "New str"
|
42
|
+
ref = Wref.new(str)
|
43
|
+
ref = nil
|
44
|
+
|
45
|
+
str2 = "New string"
|
46
|
+
ref2 = Wref.new(str2)
|
47
|
+
ref2 = nil
|
48
|
+
GC.start
|
49
|
+
end
|
50
|
+
|
51
|
+
#Test each-method.
|
52
|
+
count = 0
|
53
|
+
map.each do |a_str|
|
54
|
+
count += 1
|
55
|
+
end
|
56
|
+
|
57
|
+
raise "Expected count 0 but it wasnt: #{count}" if count != 0
|
58
|
+
raise "Should have been garbage collected but wasnt." if map.valid?(5)
|
27
59
|
end
|
28
60
|
end
|
29
61
|
end
|
data/wref.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{wref}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kasper Johansen"]
|
12
|
-
s.date = %q{2012-
|
12
|
+
s.date = %q{2012-07-01}
|
13
13
|
s.description = %q{Lightweight weak reference and weak hash that works in 1.9 and JRuby.}
|
14
14
|
s.email = %q{k@spernj.org}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: wref
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kasper Johansen
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-07-01 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
hash:
|
96
|
+
hash: 4315539060492867087
|
97
97
|
segments:
|
98
98
|
- 0
|
99
99
|
version: "0"
|