ref 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT_LICENSE +20 -0
- data/VERSION +1 -1
- data/lib/ref/mock.rb +12 -7
- data/lib/ref/reference_queue.rb +2 -2
- data/lib/ref/soft_key_map.rb +1 -1
- data/lib/ref/soft_reference.rb +1 -1
- data/lib/ref/soft_value_map.rb +1 -1
- data/lib/ref/weak_key_map.rb +1 -1
- data/lib/ref/weak_reference.rb +1 -1
- data/lib/ref/weak_value_map.rb +1 -1
- data/test/mock_test.rb +33 -0
- data/test/reference_key_map_behavior.rb +0 -2
- data/test/reference_value_map_behavior.rb +0 -2
- metadata +26 -42
data/MIT_LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Brian Durand
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
data/lib/ref/mock.rb
CHANGED
@@ -6,11 +6,11 @@ module Ref
|
|
6
6
|
#
|
7
7
|
# Example usage:
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# Ref::Mock.use do
|
10
10
|
# obj = Object.new
|
11
|
-
# ref =
|
11
|
+
# ref = Ref::WeakReference.new(obj)
|
12
12
|
# ref.object # obj
|
13
|
-
#
|
13
|
+
# Ref::Mock.gc(obj) # mimics the garbage collector reclaiming the referenced object
|
14
14
|
# ref.object # nil
|
15
15
|
# end
|
16
16
|
module Mock
|
@@ -107,11 +107,16 @@ module Ref
|
|
107
107
|
# Simulate garbage collection of the objects passed in as arguments. If no objects
|
108
108
|
# are specified, all objects will be reclaimed.
|
109
109
|
def gc(*objects)
|
110
|
-
objects =
|
111
|
-
|
112
|
-
|
110
|
+
objects = if objects.empty?
|
111
|
+
object_space.keys
|
112
|
+
else
|
113
|
+
objects.map { |obj| obj.__id__ }
|
114
|
+
end
|
115
|
+
|
116
|
+
objects.each do |id|
|
117
|
+
finalizers = object_space.delete(id)
|
113
118
|
if finalizers
|
114
|
-
finalizers.each{|finalizer| finalizer.call(
|
119
|
+
finalizers.each{|finalizer| finalizer.call(id)}
|
115
120
|
end
|
116
121
|
end
|
117
122
|
end
|
data/lib/ref/reference_queue.rb
CHANGED
@@ -13,13 +13,13 @@ module Ref
|
|
13
13
|
#
|
14
14
|
# === Example usage:
|
15
15
|
#
|
16
|
-
# class MyRef <
|
16
|
+
# class MyRef < Ref::WeakReference
|
17
17
|
# def cleanup
|
18
18
|
# # Do something...
|
19
19
|
# end
|
20
20
|
# end
|
21
21
|
#
|
22
|
-
# queue =
|
22
|
+
# queue = Ref::ReferenceQueue.new
|
23
23
|
# ref = MyRef.new(Object.new)
|
24
24
|
# queue.monitor(ref)
|
25
25
|
# queue.shift # = nil
|
data/lib/ref/soft_key_map.rb
CHANGED
data/lib/ref/soft_reference.rb
CHANGED
data/lib/ref/soft_value_map.rb
CHANGED
@@ -10,7 +10,7 @@ module Ref
|
|
10
10
|
#
|
11
11
|
# === Example usage:
|
12
12
|
#
|
13
|
-
# cache =
|
13
|
+
# cache = Ref::SoftValueMap.new
|
14
14
|
# foo = "foo"
|
15
15
|
# cache["strong"] = foo # add a value with a strong reference
|
16
16
|
# cache["soft"] = "bar" # add a value without a strong reference
|
data/lib/ref/weak_key_map.rb
CHANGED
data/lib/ref/weak_reference.rb
CHANGED
data/lib/ref/weak_value_map.rb
CHANGED
@@ -10,7 +10,7 @@ module Ref
|
|
10
10
|
#
|
11
11
|
# === Example usage:
|
12
12
|
#
|
13
|
-
# cache =
|
13
|
+
# cache = Ref::WeakValueMap.new
|
14
14
|
# foo = "foo"
|
15
15
|
# cache["strong"] = foo # add a value with a strong reference
|
16
16
|
# cache["weak"] = "bar" # add a value without a strong reference
|
data/test/mock_test.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path("../test_helper", __FILE__)
|
2
|
+
|
3
|
+
class TestMock < Test::Unit::TestCase
|
4
|
+
def test_gc_with_argument
|
5
|
+
Ref::Mock.use do
|
6
|
+
obj_1 = Object.new
|
7
|
+
obj_2 = Object.new
|
8
|
+
|
9
|
+
ref_1 = Ref::WeakReference.new(obj_1)
|
10
|
+
ref_2 = Ref::WeakReference.new(obj_2)
|
11
|
+
|
12
|
+
Ref::Mock.gc(obj_1)
|
13
|
+
|
14
|
+
assert_nil ref_1.object
|
15
|
+
assert_equal ref_2.object, obj_2
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_gc_with_no_argument
|
20
|
+
Ref::Mock.use do
|
21
|
+
obj_1 = Object.new
|
22
|
+
obj_2 = Object.new
|
23
|
+
|
24
|
+
ref_1 = Ref::WeakReference.new(obj_1)
|
25
|
+
ref_2 = Ref::WeakReference.new(obj_2)
|
26
|
+
|
27
|
+
Ref::Mock.gc
|
28
|
+
|
29
|
+
assert_nil ref_1.object
|
30
|
+
assert_nil ref_2.object
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,36 +1,29 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ref
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 1.0.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Brian Durand
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-01-11 00:00:00 -06:00
|
19
|
-
default_executable:
|
12
|
+
date: 2012-11-08 00:00:00.000000000 Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
description: Library that implements weak, soft, and strong references in Ruby that
|
15
|
+
work across multiple runtimes (MRI, REE, YARV, Jruby, Rubinius, and IronRuby). Also
|
16
|
+
includes implementation of maps/hashes that use references and a reference queue.
|
17
|
+
email:
|
24
18
|
- bdurand@embellishedvisions.com
|
25
19
|
executables: []
|
26
|
-
|
27
20
|
extensions: []
|
28
|
-
|
29
|
-
extra_rdoc_files:
|
21
|
+
extra_rdoc_files:
|
30
22
|
- README.rdoc
|
31
|
-
files:
|
23
|
+
files:
|
32
24
|
- README.rdoc
|
33
25
|
- VERSION
|
26
|
+
- MIT_LICENSE
|
34
27
|
- lib/org/jruby/ext/ref/references.jar
|
35
28
|
- lib/ref/abstract_reference_key_map.rb
|
36
29
|
- lib/ref/abstract_reference_value_map.rb
|
@@ -49,6 +42,7 @@ files:
|
|
49
42
|
- lib/ref/weak_reference.rb
|
50
43
|
- lib/ref/weak_value_map.rb
|
51
44
|
- lib/ref.rb
|
45
|
+
- test/mock_test.rb
|
52
46
|
- test/reference_key_map_behavior.rb
|
53
47
|
- test/reference_key_map_behavior.rbc
|
54
48
|
- test/reference_queue_test.rb
|
@@ -73,41 +67,31 @@ files:
|
|
73
67
|
- ext/java/org/jruby/ext/ref/ReferencesService.java
|
74
68
|
- ext/java/org/jruby/ext/ref/RubySoftReference.java
|
75
69
|
- ext/java/org/jruby/ext/ref/RubyWeakReference.java
|
76
|
-
has_rdoc: true
|
77
70
|
homepage: http://github.com/bdurand/ref
|
78
71
|
licenses: []
|
79
|
-
|
80
72
|
post_install_message:
|
81
|
-
rdoc_options:
|
73
|
+
rdoc_options:
|
82
74
|
- --charset=UTF-8
|
83
75
|
- --main
|
84
76
|
- README.rdoc
|
85
|
-
require_paths:
|
77
|
+
require_paths:
|
86
78
|
- lib
|
87
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
80
|
none: false
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
|
93
|
-
|
94
|
-
- 0
|
95
|
-
version: "0"
|
96
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
86
|
none: false
|
98
|
-
requirements:
|
99
|
-
- -
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
|
102
|
-
segments:
|
103
|
-
- 0
|
104
|
-
version: "0"
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
105
91
|
requirements: []
|
106
|
-
|
107
92
|
rubyforge_project:
|
108
|
-
rubygems_version: 1.
|
93
|
+
rubygems_version: 1.8.11
|
109
94
|
signing_key:
|
110
95
|
specification_version: 3
|
111
96
|
summary: Library that implements weak, soft, and strong references in Ruby.
|
112
97
|
test_files: []
|
113
|
-
|