wref 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e9470b819c7b11a7787df0b977af91b0d1a20af2
4
- data.tar.gz: 1abbd729851f77a36f5ebe0f8def73d73b5bd8d3
2
+ SHA256:
3
+ metadata.gz: d9218242a9315c04fb36990da5569691cd7c7e63ec836c9166c7ccd9bd7c091e
4
+ data.tar.gz: a9a2d268cb266224fcd1fb86c944947f07c7395fe4d0d49f5be954d686e15166
5
5
  SHA512:
6
- metadata.gz: 5c6fb6e08a0822a3d8a09b73f1390040b73af795dee23a2921e6600f28be809d6d05c9b321bb7f9b11b715e2f30dbca964b23269ee357da9ec85f447e6096a57
7
- data.tar.gz: d5fa295fd268ee4e1f995384ff1c1e850b8c702d23804dd816b646d6775bf8f482e3a694f4ef652281468482813bfca3654050977ab41c0d6ed4f15898ba9f90
6
+ metadata.gz: f4bd2061b3c1ff606a58297e15635927afad6a46d4c30b460f337f68f6d86eb68799a9534303b36ec5aecbc36c766a7b9585172825dfcc8627ebef8e58a2c350
7
+ data.tar.gz: 0a892a013c8c6bd141ae1d11f48d6814bac7384b610bd33729f2084604c74883b6ee70896c48cdbef3852d35353c90acebb00d6925eb88dd9348b0feb8c0176d
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
- [![Build Status](https://api.shippable.com/projects/540e7b9f3479c5ea8f9ec25e/badge?branchName=master)](https://app.shippable.com/projects/540e7b9f3479c5ea8f9ec25e/builds/latest)
2
- [![Code Climate](https://codeclimate.com/github/kaspernj/wref/badges/gpa.svg)](https://codeclimate.com/github/kaspernj/wref)
3
- [![Test Coverage](https://codeclimate.com/github/kaspernj/wref/badges/coverage.svg)](https://codeclimate.com/github/kaspernj/wref)
1
+ ![Build Status](https://www.peakflow.io/en/projects/wref/branch-statuses/master.svg)
4
2
 
5
3
  # Wref
6
4
 
@@ -29,23 +27,70 @@ weak_ref = Wref.new(str)
29
27
  weak_ref.alive? #=> true | false
30
28
  ```
31
29
 
32
- ### Weak map
30
+ ### Spawn a weak map
33
31
 
34
32
  ```ruby
35
33
  weak_map = Wref::Map.new
34
+ ```
35
+
36
+ ### Set a key and value in a weak map
37
+
38
+ ```ruby
39
+ str = "Test"
36
40
  map[1] = str
41
+ map.set(1, str)
42
+ ```
43
+
44
+ ### Get values from a weak map
45
+
46
+ ```ruby
47
+ map.get(1) #=> "Test" | nil
48
+ map.get!(1) #=> "Test" | Wref::Recycled error
49
+ ```
50
+
51
+ ### Loop over all valid pairs in a weak map
52
+
53
+ ```ruby
54
+ map.each do |key, value|
55
+ puts "Valid pair: #{key}: #{value}"
56
+ end
37
57
  ```
38
58
 
39
59
  ### Check if key is valid in a weak map.
40
60
 
41
61
  ```ruby
42
- weak_map.valid?(1) #=> true | false
62
+ map.valid?(1) #=> true | false
63
+ ```
64
+
65
+ ### Getting length of both valid and invalid and the current time in a weak map (fastest)
66
+
67
+ ```ruby
68
+ map.length #=> 1
69
+ ```
70
+
71
+ ### Getting length of valid options in a weak map
72
+
73
+ ```ruby
74
+ map.length_valid #=> 0
43
75
  ```
44
76
 
45
77
  ### Get from a key
46
78
 
47
79
  ```ruby
48
- weak_map.get(1) #=> "Test" | Error - Wref::Recycled
80
+ map.get(1) #=> "Test" | nil
81
+ map.get!(1) #=> "Test" | Error - Wref::Recycled
82
+ ```
83
+
84
+ ### Delete a key from a weak map
85
+
86
+ ```ruby
87
+ map.delete(1) #=> "Test" | nil if recycled
88
+ ```
89
+
90
+ ### Delete all recycled options
91
+
92
+ ```ruby
93
+ map.clean
49
94
  ```
50
95
 
51
96
  ## Contributing to wref
data/Rakefile CHANGED
@@ -11,20 +11,6 @@ rescue Bundler::BundlerError => e
11
11
  end
12
12
  require 'rake'
13
13
 
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "wref"
18
- gem.homepage = "http://github.com/kaspernj/wref"
19
- gem.license = "MIT"
20
- gem.summary = %Q{Weak references and weak hash for Ruby}
21
- gem.description = %Q{Lightweight weak reference and weak hash that works in 1.9 and JRuby.}
22
- gem.email = "k@spernj.org"
23
- gem.authors = ["Kasper Johansen"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
14
  require 'rspec/core'
29
15
  require 'rspec/core/rake_task'
30
16
  RSpec::Core::RakeTask.new(:spec) do |spec|
@@ -40,7 +26,7 @@ task :default => :spec
40
26
 
41
27
  require 'rdoc/task'
42
28
  Rake::RDocTask.new do |rdoc|
43
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
29
+ version = File.read('VERSION')
44
30
 
45
31
  rdoc.rdoc_dir = 'rdoc'
46
32
  rdoc.title = "wref #{version}"
@@ -14,7 +14,13 @@ class Wref::Implementations::IdClassUnique
14
14
 
15
15
  def get
16
16
  return nil if !@class_name || !@id
17
- object = ObjectSpace._id2ref(@id)
17
+
18
+ begin
19
+ object = ObjectSpace._id2ref(@id)
20
+ rescue RangeError
21
+ destroy
22
+ return nil
23
+ end
18
24
 
19
25
  #Some times this class-name will be nil for some reason - knj
20
26
  object_class_name = object.class.name
data/lib/wref/map.rb CHANGED
@@ -70,7 +70,8 @@ class Wref::Map
70
70
  end
71
71
  end
72
72
 
73
- #Scans the whole map and removes dead references. After the implementation of automatic clean-up by using ObjectSpace.define_finalizer, there should be no reason to call this method.
73
+ # Scans the whole map and removes dead references. After the implementation of automatic clean-up by using ObjectSpace.define_finalizer,
74
+ # there should be no reason to call this method.
74
75
  def clean
75
76
  keys = nil
76
77
  @mutex.synchronize do
@@ -168,6 +169,48 @@ class Wref::Map
168
169
  end
169
170
  end
170
171
 
172
+ def each_key(&block)
173
+ enum = Enumerator.new do |yielder|
174
+ ids = nil
175
+ @mutex.synchronize do
176
+ ids = @map.keys
177
+ end
178
+
179
+ ids.each do |id|
180
+ if obj = get(id)
181
+ yielder << id
182
+ end
183
+ end
184
+ end
185
+
186
+ if block
187
+ enum.each(&block)
188
+ else
189
+ return enum
190
+ end
191
+ end
192
+
193
+ def each_value(&block)
194
+ enum = Enumerator.new do |yielder|
195
+ ids = nil
196
+ @mutex.synchronize do
197
+ ids = @map.keys
198
+ end
199
+
200
+ ids.each do |id|
201
+ if obj = get(id)
202
+ yielder << obj
203
+ end
204
+ end
205
+ end
206
+
207
+ if block
208
+ enum.each(&block)
209
+ else
210
+ return enum
211
+ end
212
+ end
213
+
171
214
  #Make it hash-compatible.
172
215
  alias has_key? key?
173
216
  alias [] get
data/lib/wref.rb CHANGED
@@ -33,9 +33,9 @@ class Wref
33
33
  attr_reader :implementation, :weak_ref
34
34
 
35
35
  #Initializes various variables.
36
- def initialize(object, args = {})
37
- if args[:impl]
38
- @implementation = args[:impl]
36
+ def initialize(object, impl: nil)
37
+ if impl
38
+ @implementation = impl
39
39
  elsif RUBY_ENGINE == "jruby"
40
40
  @implementation = :JavaWeakReference
41
41
  else
metadata CHANGED
@@ -1,79 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wref
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
- - Kasper Johansen
7
+ - Kasper Stöckel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-08 00:00:00.000000000 Z
11
+ date: 2024-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 3.2.0
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 3.2.0
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 1.9.2
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 1.9.2
41
- - !ruby/object:Gem::Dependency
42
- name: jeweler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 1.8.8
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 1.8.8
55
- - !ruby/object:Gem::Dependency
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
14
+ name: ref
71
15
  requirement: !ruby/object:Gem::Requirement
72
16
  requirements:
73
17
  - - ">="
74
18
  - !ruby/object:Gem::Version
75
19
  version: '0'
76
- type: :development
20
+ type: :runtime
77
21
  prerelease: false
78
22
  version_requirements: !ruby/object:Gem::Requirement
79
23
  requirements:
@@ -81,13 +25,13 @@ dependencies:
81
25
  - !ruby/object:Gem::Version
82
26
  version: '0'
83
27
  - !ruby/object:Gem::Dependency
84
- name: ref
28
+ name: weakling
85
29
  requirement: !ruby/object:Gem::Requirement
86
30
  requirements:
87
31
  - - ">="
88
32
  - !ruby/object:Gem::Version
89
33
  version: '0'
90
- type: :development
34
+ type: :runtime
91
35
  prerelease: false
92
36
  version_requirements: !ruby/object:Gem::Requirement
93
37
  requirements:
@@ -102,14 +46,9 @@ extra_rdoc_files:
102
46
  - LICENSE.txt
103
47
  - README.md
104
48
  files:
105
- - ".document"
106
- - ".rspec"
107
- - Gemfile
108
- - Gemfile.lock
109
49
  - LICENSE.txt
110
50
  - README.md
111
51
  - Rakefile
112
- - VERSION
113
52
  - lib/wref.rb
114
53
  - lib/wref/implementations/id_class_unique.rb
115
54
  - lib/wref/implementations/java_weak_reference.rb
@@ -117,19 +56,6 @@ files:
117
56
  - lib/wref/implementations/weak_ref.rb
118
57
  - lib/wref/implementations/weakling.rb
119
58
  - 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
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
131
- - spec/wref_spec.rb
132
- - wref.gemspec
133
59
  homepage: http://github.com/kaspernj/wref
134
60
  licenses:
135
61
  - MIT
@@ -149,8 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
75
  - !ruby/object:Gem::Version
150
76
  version: '0'
151
77
  requirements: []
152
- rubyforge_project:
153
- rubygems_version: 2.4.0
78
+ rubygems_version: 3.4.17
154
79
  signing_key:
155
80
  specification_version: 4
156
81
  summary: Weak references and weak hash for Ruby
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
data/Gemfile DELETED
@@ -1,17 +0,0 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "rspec", "~> 3.2.0"
10
- gem "bundler", "~> 1.9.2"
11
- gem "jeweler", "~> 1.8.8"
12
- gem "highline", "~> 1.6.21"
13
- gem "weakling"
14
- gem "ref"
15
- end
16
-
17
- gem "codeclimate-test-reporter", group: :test, require: nil
data/Gemfile.lock DELETED
@@ -1,81 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- addressable (2.3.8)
5
- builder (3.2.2)
6
- codeclimate-test-reporter (0.4.7)
7
- simplecov (>= 0.7.1, < 1.0.0)
8
- diff-lcs (1.2.5)
9
- docile (1.1.5)
10
- faraday (0.8.9)
11
- multipart-post (~> 1.2.0)
12
- git (1.2.9.1)
13
- github_api (0.10.1)
14
- addressable
15
- faraday (~> 0.8.1)
16
- hashie (>= 1.2)
17
- multi_json (~> 1.4)
18
- nokogiri (~> 1.5.2)
19
- oauth2
20
- hashie (3.4.1)
21
- highline (1.6.21)
22
- jeweler (1.8.8)
23
- builder
24
- bundler (~> 1.0)
25
- git (>= 1.2.5)
26
- github_api (= 0.10.1)
27
- highline (>= 1.6.15)
28
- nokogiri (= 1.5.10)
29
- rake
30
- rdoc
31
- json (1.8.2)
32
- json (1.8.2-java)
33
- jwt (1.4.1)
34
- multi_json (1.11.0)
35
- multi_xml (0.5.5)
36
- multipart-post (1.2.0)
37
- nokogiri (1.5.10)
38
- nokogiri (1.5.10-java)
39
- oauth2 (1.0.0)
40
- faraday (>= 0.8, < 0.10)
41
- jwt (~> 1.0)
42
- multi_json (~> 1.3)
43
- multi_xml (~> 0.5)
44
- rack (~> 1.2)
45
- rack (1.6.0)
46
- rake (10.4.2)
47
- rdoc (4.2.0)
48
- json (~> 1.4)
49
- ref (1.0.5)
50
- rspec (3.2.0)
51
- rspec-core (~> 3.2.0)
52
- rspec-expectations (~> 3.2.0)
53
- rspec-mocks (~> 3.2.0)
54
- rspec-core (3.2.2)
55
- rspec-support (~> 3.2.0)
56
- rspec-expectations (3.2.0)
57
- diff-lcs (>= 1.2.0, < 2.0)
58
- rspec-support (~> 3.2.0)
59
- rspec-mocks (3.2.1)
60
- diff-lcs (>= 1.2.0, < 2.0)
61
- rspec-support (~> 3.2.0)
62
- rspec-support (3.2.2)
63
- simplecov (0.9.2)
64
- docile (~> 1.1.0)
65
- multi_json (~> 1.0)
66
- simplecov-html (~> 0.9.0)
67
- simplecov-html (0.9.0)
68
- weakling (0.0.3)
69
-
70
- PLATFORMS
71
- java
72
- ruby
73
-
74
- DEPENDENCIES
75
- bundler (~> 1.9.2)
76
- codeclimate-test-reporter
77
- highline (~> 1.6.21)
78
- jeweler (~> 1.8.8)
79
- ref
80
- rspec (~> 3.2.0)
81
- weakling
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.7
data/shippable.yml DELETED
@@ -1,12 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - ruby-head
4
- - ruby-2.1-head
5
- - ruby-2.0-head
6
- - ruby-1.9.3-head
7
- - ruby-1.9.2-head
8
- - jruby-head
9
- script:
10
- - CODECLIMATE_REPO_TOKEN=23d002ad9b86687a067e6bbc81320cd979ffad756d1be69ca4e24c1038ee19a6 bundle exec rspec
11
- notifications:
12
- email: false
@@ -1,6 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Wref::Implementations::IdClassUnique do
4
- it_should_behave_like "wref" unless RUBY_ENGINE == "jruby"
5
- it_should_behave_like "map" unless RUBY_ENGINE == "jruby"
6
- end
@@ -1,6 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Wref::Implementations::JavaWeakReference do
4
- it_should_behave_like "wref" if RUBY_ENGINE == "jruby"
5
- it_should_behave_like "map" if RUBY_ENGINE == "jruby"
6
- end
@@ -1,6 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Wref::Implementations::Ref do
4
- it_should_behave_like "wref"
5
- it_should_behave_like "map"
6
- end
@@ -1,6 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Wref::Implementations::WeakRef do
4
- it_should_behave_like "wref"
5
- it_should_behave_like "map"
6
- end
@@ -1,6 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Wref::Implementations::Weakling do
4
- it_should_behave_like "wref" if RUBY_ENGINE == "jruby"
5
- it_should_behave_like "map" if RUBY_ENGINE == "jruby"
6
- end
data/spec/spec_helper.rb DELETED
@@ -1,19 +0,0 @@
1
- require "codeclimate-test-reporter"
2
- CodeClimate::TestReporter.start
3
-
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
- $LOAD_PATH.unshift(File.dirname(__FILE__))
6
- require "rspec"
7
- require "wref"
8
- require "weakling" if RUBY_ENGINE == "jruby"
9
- require "ref"
10
-
11
- # Requires supporting files with custom matchers and macros, etc,
12
- # in ./support/ and its subdirectories.
13
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
14
-
15
- RSpec.configure do |config|
16
- config.expect_with :rspec do |c|
17
- c.syntax = [:should, :expect]
18
- end
19
- end
@@ -1,33 +0,0 @@
1
- module GarbageCollectorHelper
2
- def force_garbage_collect
3
- GC.enable
4
-
5
- sleep 0.01
6
-
7
- if RUBY_ENGINE == "jruby"
8
- java.lang.System.gc
9
- else
10
- if RUBY_VERSION.start_with?("2")
11
- GC.start(full_mark: true, immediate_sweep: true)
12
- else
13
- GC.start
14
- end
15
- end
16
-
17
- sleep 0.01
18
-
19
- GC.disable
20
- end
21
-
22
- def force_garbage_collection
23
- force_garbage_collect
24
-
25
- 10000.times do
26
- some_str = User.new("User #{Digest::MD5.hexdigest(Time.now.to_f.to_s)}")
27
- weak_ref = described_class.new(some_str)
28
- some_str = nil
29
- end
30
-
31
- force_garbage_collect
32
- end
33
- end
@@ -1,87 +0,0 @@
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
data/spec/support/user.rb DELETED
@@ -1,8 +0,0 @@
1
- # Sample class that is used for testing.
2
- class User
3
- attr_reader :name
4
-
5
- def initialize(name)
6
- @name = name
7
- end
8
- end
@@ -1,68 +0,0 @@
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 DELETED
@@ -1,6 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Wref do
4
- it_should_behave_like "wref"
5
- it_should_behave_like "map"
6
- end
data/wref.gemspec DELETED
@@ -1,83 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: wref 0.0.7 ruby lib
6
-
7
- Gem::Specification.new do |s|
8
- s.name = "wref"
9
- s.version = "0.0.7"
10
-
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Kasper Johansen"]
14
- s.date = "2015-04-08"
15
- s.description = "Lightweight weak reference and weak hash that works in 1.9 and JRuby."
16
- s.email = "k@spernj.org"
17
- s.extra_rdoc_files = [
18
- "LICENSE.txt",
19
- "README.md"
20
- ]
21
- s.files = [
22
- ".document",
23
- ".rspec",
24
- "Gemfile",
25
- "Gemfile.lock",
26
- "LICENSE.txt",
27
- "README.md",
28
- "Rakefile",
29
- "VERSION",
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",
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",
48
- "spec/wref_spec.rb",
49
- "wref.gemspec"
50
- ]
51
- s.homepage = "http://github.com/kaspernj/wref"
52
- s.licenses = ["MIT"]
53
- s.rubygems_version = "2.4.0"
54
- s.summary = "Weak references and weak hash for Ruby"
55
-
56
- if s.respond_to? :specification_version then
57
- s.specification_version = 4
58
-
59
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
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"])
66
- else
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"])
73
- end
74
- else
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"])
81
- end
82
- end
83
-