wref 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +8 -4
- data/Gemfile.lock +68 -18
- data/README.md +65 -0
- data/VERSION +1 -1
- data/lib/wref.rb +38 -271
- data/lib/wref/implementations/id_class_unique.rb +50 -0
- data/lib/wref/implementations/java_weak_reference.rb +26 -0
- data/lib/wref/implementations/ref.rb +24 -0
- data/lib/wref/implementations/weak_ref.rb +53 -0
- data/lib/wref/implementations/weakling.rb +31 -0
- data/lib/wref/map.rb +175 -0
- data/shippable.yml +12 -0
- data/spec/implementations/id_class_unique_spec.rb +6 -0
- data/spec/implementations/java_weak_reference_spec.rb +6 -0
- data/spec/implementations/ref_spec.rb +6 -0
- data/spec/implementations/weak_ref_spec.rb +6 -0
- data/spec/implementations/weakling_spec.rb +6 -0
- data/spec/spec_helper.rb +10 -3
- data/spec/support/garbage_collector_helper.rb +33 -0
- data/spec/support/map_collection.rb +87 -0
- data/spec/support/user.rb +8 -0
- data/spec/support/wref_collection.rb +68 -0
- data/spec/wref_spec.rb +5 -63
- data/wref.gemspec +42 -19
- metadata +74 -43
- data/README.rdoc +0 -19
@@ -0,0 +1,87 @@
|
|
1
|
+
shared_examples_for "map" do
|
2
|
+
include GarbageCollectorHelper
|
3
|
+
|
4
|
+
let(:user) { User.new("Kasper") }
|
5
|
+
|
6
|
+
let(:map) do
|
7
|
+
class_name = described_class.name
|
8
|
+
|
9
|
+
if match = class_name.match(/::([A-z]+)$/)
|
10
|
+
impl = match[1].to_sym if match[1] != "Map"
|
11
|
+
end
|
12
|
+
|
13
|
+
map = Wref::Map.new(impl: impl)
|
14
|
+
map[5] = user
|
15
|
+
map[6] = User.new("Morten")
|
16
|
+
map
|
17
|
+
end
|
18
|
+
|
19
|
+
it "#valid?" do
|
20
|
+
map.valid?(5).should eq true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "#each" do
|
24
|
+
count = 0
|
25
|
+
str_col = ""
|
26
|
+
key_col = ""
|
27
|
+
|
28
|
+
map.each do |key, user|
|
29
|
+
count += 1
|
30
|
+
str_col << user.name
|
31
|
+
key_col << key.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
key_col.should eq "56"
|
35
|
+
str_col.should eq "KasperMorten"
|
36
|
+
count.should eq 2
|
37
|
+
end
|
38
|
+
|
39
|
+
it "#length" do
|
40
|
+
map.length.should eq 2
|
41
|
+
end
|
42
|
+
|
43
|
+
it "#length_valid" do
|
44
|
+
map.length_valid.should eq 2
|
45
|
+
|
46
|
+
force_garbage_collection
|
47
|
+
|
48
|
+
map.length_valid.should eq 1
|
49
|
+
end
|
50
|
+
|
51
|
+
it "#delete" do
|
52
|
+
map.delete(5).should === user
|
53
|
+
map.length.should eq 1
|
54
|
+
map.length_valid.should eq 1
|
55
|
+
end
|
56
|
+
|
57
|
+
it "#key?" do
|
58
|
+
map.key?(5).should eq true
|
59
|
+
map.key?(6).should eq true
|
60
|
+
map.key?(7).should eq false
|
61
|
+
|
62
|
+
force_garbage_collection
|
63
|
+
|
64
|
+
map.key?(6).should eq false
|
65
|
+
end
|
66
|
+
|
67
|
+
it "works with gc" do
|
68
|
+
map
|
69
|
+
force_garbage_collection
|
70
|
+
|
71
|
+
#Test each-method.
|
72
|
+
count = 0
|
73
|
+
map.each do |key, a_str|
|
74
|
+
count += 1
|
75
|
+
end
|
76
|
+
|
77
|
+
count.should eq 1
|
78
|
+
map.valid?(5).should eq true
|
79
|
+
map.valid?(6).should eq false
|
80
|
+
|
81
|
+
map.get(5).should === user
|
82
|
+
map.get(6).should eq nil
|
83
|
+
|
84
|
+
map.get!(5).should === user
|
85
|
+
expect { map.get!(6) }.to raise_error(Wref::Recycled)
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
shared_examples_for "wref" do
|
2
|
+
include GarbageCollectorHelper
|
3
|
+
|
4
|
+
let(:implementation) do
|
5
|
+
class_name = described_class.name
|
6
|
+
|
7
|
+
if match = class_name.match(/::([A-z]+)$/)
|
8
|
+
impl = match[1].to_sym if match[1] != "Map"
|
9
|
+
end
|
10
|
+
|
11
|
+
return impl
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:user) { User.new("Kasper") }
|
15
|
+
let(:user_ref) { Wref.new(user, impl: implementation) }
|
16
|
+
|
17
|
+
def ref_in_danger
|
18
|
+
return Wref.new(User.new("Morten"), impl: implementation)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "#implementation" do
|
22
|
+
user_ref.implementation.should eq implementation if described_class != Wref
|
23
|
+
end
|
24
|
+
|
25
|
+
it "#weak_ref" do
|
26
|
+
user_ref.weak_ref.should be_a described_class if described_class != Wref
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#alive?" do
|
30
|
+
it "is true when ref exists" do
|
31
|
+
user_ref.alive?.should eq true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "is false when ref has been removed" do
|
35
|
+
ref = ref_in_danger
|
36
|
+
force_garbage_collection
|
37
|
+
ref.alive?.should eq false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#get" do
|
42
|
+
it "#get" do
|
43
|
+
user_ref.get.name.should eq "Kasper"
|
44
|
+
ref2 = ref_in_danger
|
45
|
+
|
46
|
+
force_garbage_collection
|
47
|
+
|
48
|
+
user_ref.get.should === user
|
49
|
+
ref2.get.should eq nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns the correct content initialy" do
|
53
|
+
ref_in_danger.get.name.should eq "Morten"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "#get!" do
|
58
|
+
ref = user_ref
|
59
|
+
ref.get!.should === user
|
60
|
+
|
61
|
+
ref2 = ref_in_danger
|
62
|
+
|
63
|
+
force_garbage_collection
|
64
|
+
|
65
|
+
ref.get!.should === user
|
66
|
+
expect { ref2.get! }.to raise_error Wref::Recycled
|
67
|
+
end
|
68
|
+
end
|
data/spec/wref_spec.rb
CHANGED
@@ -1,64 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
str = "Test"
|
8
|
-
ref = Wref.new(str)
|
9
|
-
raise "Should have been alive but wasnt." if !ref.alive?
|
10
|
-
str = nil
|
11
|
-
|
12
|
-
#In MRI we have to define another object finalizer, before the last will be finalized.
|
13
|
-
str2 = "Test 2"
|
14
|
-
ref2 = Wref.new(str2)
|
15
|
-
ref2 = nil
|
16
|
-
GC.start
|
17
|
-
raise "Should have been GCed but wasnt." if ref.alive?
|
18
|
-
|
19
|
-
|
20
|
-
str = "Test"
|
21
|
-
map = Wref_map.new
|
22
|
-
map[5] = str
|
23
|
-
map[6] = "trala"
|
24
|
-
|
25
|
-
raise "Should have been valid but wasnt." if !map.valid?(5)
|
26
|
-
str = nil
|
27
|
-
|
28
|
-
#Test each-method.
|
29
|
-
count = 0
|
30
|
-
str_col = ""
|
31
|
-
key_col = ""
|
32
|
-
map.each do |key, a_str|
|
33
|
-
count += 1
|
34
|
-
str_col << a_str
|
35
|
-
key_col << key.to_s
|
36
|
-
end
|
37
|
-
|
38
|
-
raise "Expected key-collection to be '56' but it wasnt: #{key_col}" if key_col != "56"
|
39
|
-
raise "Expected collection to be 'Testtrala' but it wasnt: #{str_col}" if str_col != "Testtrala"
|
40
|
-
raise "Expected count 2 but it wasnt: #{count}" if count != 2
|
41
|
-
|
42
|
-
#Make the engine work a little to force garbage collection.
|
43
|
-
0.upto(10) do
|
44
|
-
str = "New str"
|
45
|
-
ref = Wref.new(str)
|
46
|
-
ref = nil
|
47
|
-
|
48
|
-
str2 = "New string"
|
49
|
-
ref2 = Wref.new(str2)
|
50
|
-
ref2 = nil
|
51
|
-
GC.start
|
52
|
-
end
|
53
|
-
|
54
|
-
#Test each-method.
|
55
|
-
count = 0
|
56
|
-
map.each do |key, a_str|
|
57
|
-
count += 1
|
58
|
-
end
|
59
|
-
|
60
|
-
raise "Expected count 0 but it wasnt: #{count}" if count != 0
|
61
|
-
raise "Should have been garbage collected but wasnt." if map.valid?(5)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
3
|
+
describe Wref do
|
4
|
+
it_should_behave_like "wref"
|
5
|
+
it_should_behave_like "map"
|
6
|
+
end
|
data/wref.gemspec
CHANGED
@@ -2,19 +2,21 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: wref 0.0.7 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "wref"
|
8
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.7"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
11
13
|
s.authors = ["Kasper Johansen"]
|
12
|
-
s.date = "
|
14
|
+
s.date = "2015-04-08"
|
13
15
|
s.description = "Lightweight weak reference and weak hash that works in 1.9 and JRuby."
|
14
16
|
s.email = "k@spernj.org"
|
15
17
|
s.extra_rdoc_files = [
|
16
18
|
"LICENSE.txt",
|
17
|
-
"README.
|
19
|
+
"README.md"
|
18
20
|
]
|
19
21
|
s.files = [
|
20
22
|
".document",
|
@@ -22,39 +24,60 @@ Gem::Specification.new do |s|
|
|
22
24
|
"Gemfile",
|
23
25
|
"Gemfile.lock",
|
24
26
|
"LICENSE.txt",
|
25
|
-
"README.
|
27
|
+
"README.md",
|
26
28
|
"Rakefile",
|
27
29
|
"VERSION",
|
28
30
|
"lib/wref.rb",
|
31
|
+
"lib/wref/implementations/id_class_unique.rb",
|
32
|
+
"lib/wref/implementations/java_weak_reference.rb",
|
33
|
+
"lib/wref/implementations/ref.rb",
|
34
|
+
"lib/wref/implementations/weak_ref.rb",
|
35
|
+
"lib/wref/implementations/weakling.rb",
|
36
|
+
"lib/wref/map.rb",
|
37
|
+
"shippable.yml",
|
38
|
+
"spec/implementations/id_class_unique_spec.rb",
|
39
|
+
"spec/implementations/java_weak_reference_spec.rb",
|
40
|
+
"spec/implementations/ref_spec.rb",
|
41
|
+
"spec/implementations/weak_ref_spec.rb",
|
42
|
+
"spec/implementations/weakling_spec.rb",
|
29
43
|
"spec/spec_helper.rb",
|
44
|
+
"spec/support/garbage_collector_helper.rb",
|
45
|
+
"spec/support/map_collection.rb",
|
46
|
+
"spec/support/user.rb",
|
47
|
+
"spec/support/wref_collection.rb",
|
30
48
|
"spec/wref_spec.rb",
|
31
49
|
"wref.gemspec"
|
32
50
|
]
|
33
51
|
s.homepage = "http://github.com/kaspernj/wref"
|
34
52
|
s.licenses = ["MIT"]
|
35
|
-
s.
|
36
|
-
s.rubygems_version = "1.8.25"
|
53
|
+
s.rubygems_version = "2.4.0"
|
37
54
|
s.summary = "Weak references and weak hash for Ruby"
|
38
55
|
|
39
56
|
if s.respond_to? :specification_version then
|
40
|
-
s.specification_version =
|
57
|
+
s.specification_version = 4
|
41
58
|
|
42
59
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
-
s.add_development_dependency(%q<rspec>, ["~> 2.
|
44
|
-
s.add_development_dependency(%q<
|
45
|
-
s.add_development_dependency(%q<
|
46
|
-
s.add_development_dependency(%q<
|
60
|
+
s.add_development_dependency(%q<rspec>, ["~> 3.2.0"])
|
61
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.9.2"])
|
62
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.8"])
|
63
|
+
s.add_development_dependency(%q<highline>, ["~> 1.6.21"])
|
64
|
+
s.add_development_dependency(%q<weakling>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<ref>, [">= 0"])
|
47
66
|
else
|
48
|
-
s.add_dependency(%q<rspec>, ["~> 2.
|
49
|
-
s.add_dependency(%q<
|
50
|
-
s.add_dependency(%q<
|
51
|
-
s.add_dependency(%q<
|
67
|
+
s.add_dependency(%q<rspec>, ["~> 3.2.0"])
|
68
|
+
s.add_dependency(%q<bundler>, ["~> 1.9.2"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.8"])
|
70
|
+
s.add_dependency(%q<highline>, ["~> 1.6.21"])
|
71
|
+
s.add_dependency(%q<weakling>, [">= 0"])
|
72
|
+
s.add_dependency(%q<ref>, [">= 0"])
|
52
73
|
end
|
53
74
|
else
|
54
|
-
s.add_dependency(%q<rspec>, ["~> 2.
|
55
|
-
s.add_dependency(%q<
|
56
|
-
s.add_dependency(%q<
|
57
|
-
s.add_dependency(%q<
|
75
|
+
s.add_dependency(%q<rspec>, ["~> 3.2.0"])
|
76
|
+
s.add_dependency(%q<bundler>, ["~> 1.9.2"])
|
77
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.8"])
|
78
|
+
s.add_dependency(%q<highline>, ["~> 1.6.21"])
|
79
|
+
s.add_dependency(%q<weakling>, [">= 0"])
|
80
|
+
s.add_dependency(%q<ref>, [">= 0"])
|
58
81
|
end
|
59
82
|
end
|
60
83
|
|
metadata
CHANGED
@@ -1,126 +1,157 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wref
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Kasper Johansen
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-04-08 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 2.
|
19
|
+
version: 3.2.0
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: 2.
|
26
|
+
version: 3.2.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
28
|
+
name: bundler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
33
|
+
version: 1.9.2
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
40
|
+
version: 1.9.2
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
42
|
+
name: jeweler
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: 1.
|
47
|
+
version: 1.8.8
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
54
|
+
version: 1.8.8
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
56
|
+
name: highline
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.6.21
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.6.21
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: weakling
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: ref
|
64
85
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
86
|
requirements:
|
67
|
-
- -
|
87
|
+
- - ">="
|
68
88
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
89
|
+
version: '0'
|
70
90
|
type: :development
|
71
91
|
prerelease: false
|
72
92
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
93
|
requirements:
|
75
|
-
- -
|
94
|
+
- - ">="
|
76
95
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
96
|
+
version: '0'
|
78
97
|
description: Lightweight weak reference and weak hash that works in 1.9 and JRuby.
|
79
98
|
email: k@spernj.org
|
80
99
|
executables: []
|
81
100
|
extensions: []
|
82
101
|
extra_rdoc_files:
|
83
102
|
- LICENSE.txt
|
84
|
-
- README.
|
103
|
+
- README.md
|
85
104
|
files:
|
86
|
-
- .document
|
87
|
-
- .rspec
|
105
|
+
- ".document"
|
106
|
+
- ".rspec"
|
88
107
|
- Gemfile
|
89
108
|
- Gemfile.lock
|
90
109
|
- LICENSE.txt
|
91
|
-
- README.
|
110
|
+
- README.md
|
92
111
|
- Rakefile
|
93
112
|
- VERSION
|
94
113
|
- lib/wref.rb
|
114
|
+
- lib/wref/implementations/id_class_unique.rb
|
115
|
+
- lib/wref/implementations/java_weak_reference.rb
|
116
|
+
- lib/wref/implementations/ref.rb
|
117
|
+
- lib/wref/implementations/weak_ref.rb
|
118
|
+
- lib/wref/implementations/weakling.rb
|
119
|
+
- lib/wref/map.rb
|
120
|
+
- shippable.yml
|
121
|
+
- spec/implementations/id_class_unique_spec.rb
|
122
|
+
- spec/implementations/java_weak_reference_spec.rb
|
123
|
+
- spec/implementations/ref_spec.rb
|
124
|
+
- spec/implementations/weak_ref_spec.rb
|
125
|
+
- spec/implementations/weakling_spec.rb
|
95
126
|
- spec/spec_helper.rb
|
127
|
+
- spec/support/garbage_collector_helper.rb
|
128
|
+
- spec/support/map_collection.rb
|
129
|
+
- spec/support/user.rb
|
130
|
+
- spec/support/wref_collection.rb
|
96
131
|
- spec/wref_spec.rb
|
97
132
|
- wref.gemspec
|
98
133
|
homepage: http://github.com/kaspernj/wref
|
99
134
|
licenses:
|
100
135
|
- MIT
|
136
|
+
metadata: {}
|
101
137
|
post_install_message:
|
102
138
|
rdoc_options: []
|
103
139
|
require_paths:
|
104
140
|
- lib
|
105
141
|
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
142
|
requirements:
|
108
|
-
- -
|
143
|
+
- - ">="
|
109
144
|
- !ruby/object:Gem::Version
|
110
145
|
version: '0'
|
111
|
-
segments:
|
112
|
-
- 0
|
113
|
-
hash: -3186907571607769173
|
114
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
-
none: false
|
116
147
|
requirements:
|
117
|
-
- -
|
148
|
+
- - ">="
|
118
149
|
- !ruby/object:Gem::Version
|
119
150
|
version: '0'
|
120
151
|
requirements: []
|
121
152
|
rubyforge_project:
|
122
|
-
rubygems_version:
|
153
|
+
rubygems_version: 2.4.0
|
123
154
|
signing_key:
|
124
|
-
specification_version:
|
155
|
+
specification_version: 4
|
125
156
|
summary: Weak references and weak hash for Ruby
|
126
157
|
test_files: []
|