rufus-lru 1.0.5 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d40c5ee89890b41593bb60c367782f88f3161f19
4
+ data.tar.gz: cc2e44a4052e047fcc8d19023e07f0c48697dba4
5
+ SHA512:
6
+ metadata.gz: 74bcdcd1aac5ce64c9df134a13c83835e749ed019d374c9915ea200229588e2f749f4031a93f9a7a9b2c01b16639586adf0b655d84f8f0971ccd9259d7827aa0
7
+ data.tar.gz: 12fb4a8406a3026f9957e9f48770d9aa5a8bf3d369ee04c6bde4b6411fadffcf06c85ad78bcf0cd54d4b0dc6f3acd1da9218bca144de39d42da4e6f07eee81ee
data/CHANGELOG.txt CHANGED
@@ -2,6 +2,18 @@
2
2
  = rufus-lru CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-lru - 1.0.7 released 2016/05/07
6
+
7
+ - modernized spec/
8
+ - switched from Rake to Make
9
+
10
+
11
+ == rufus-lru - 1.0.6 not released
12
+
13
+ - introduced manual #squeeze!
14
+ - handling values with destructor #clear
15
+
16
+
5
17
  == rufus-lru - 1.0.5 released 2012/02/28
6
18
 
7
19
  - introduced Rufus::Lru::SynchronizedHash (thread-safe)
data/CREDITS.txt ADDED
@@ -0,0 +1,14 @@
1
+
2
+ = CREDITS.txt
3
+
4
+
5
+ == Contributors
6
+
7
+ - Gleb Kuzmenko - https://github.com/bayclosed - squeeze! and more
8
+ - Baldur Gudbjornsson - https://github.com/baldur
9
+
10
+
11
+ == Feedback
12
+
13
+ - many people
14
+
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2007-2012, John Mettraux, jmettraux@gmail.com
2
+ Copyright (c) 2007-2016, John Mettraux, jmettraux@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/Makefile ADDED
@@ -0,0 +1,23 @@
1
+
2
+ NAME = \
3
+ $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name")
4
+ VERSION = \
5
+ $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.version")
6
+
7
+
8
+ gemspec_validate:
9
+ @echo "---"
10
+ ruby -e "s = eval(File.read(Dir['*.gemspec'].first)); p s.validate"
11
+ @echo "---"
12
+
13
+ name: gemspec_validate
14
+ @echo "$(NAME) $(VERSION)"
15
+
16
+ build: gemspec_validate
17
+ gem build $(NAME).gemspec
18
+ mkdir -p pkg
19
+ mv $(NAME)-$(VERSION).gem pkg/
20
+
21
+ push: build
22
+ gem push pkg/$(NAME)-$(VERSION).gem
23
+
data/README.md CHANGED
@@ -1,12 +1,23 @@
1
1
 
2
2
  # rufus-lru
3
3
 
4
+ [![Build Status](https://secure.travis-ci.org/jmettraux/rufus-lru.svg)](http://travis-ci.org/jmettraux/rufus-lru)
5
+ [![Gem Version](https://badge.fury.io/rb/rufus-lru.svg)](http://badge.fury.io/rb/rufus-lru)
6
+
4
7
  LruHash class, a Hash with a max size, controlled by a LRU mechanism.
5
8
 
6
9
 
7
10
  ## getting it
8
11
 
9
- gem install rufus-lru
12
+ ```
13
+ gem install rufus-lru
14
+ ```
15
+
16
+ or better, simply add to your ```Gemfile```
17
+
18
+ ```
19
+ gem 'rufus-lru'
20
+ ```
10
21
 
11
22
 
12
23
  ## usage
@@ -16,27 +27,81 @@ It's a regular hash, but you have to set a maxsize at instantiation.
16
27
  Once the maxsize is reached, the hash will discard the element that was the
17
28
  least recently used (hence LRU).
18
29
 
19
- require 'rubygems'
20
- require 'rufus-lru'
30
+ ```ruby
31
+ require 'rufus-lru'
21
32
 
22
- h = Rufus::Lru::Hash.new(3)
33
+ h = Rufus::Lru::Hash.new(3)
23
34
 
24
- 5.times { |i| h[i] = "a" * i }
35
+ 5.times { |i| h[i] = "a" * i }
25
36
 
26
- puts h.inspect # >> {2=>"aa", 3=>"aaa", 4=>"aaaa"}
37
+ puts h.inspect # >> {2=>"aa", 3=>"aaa", 4=>"aaaa"}
27
38
 
28
- h[:newer] = 'b'
39
+ h[:newer] = 'b'
29
40
 
30
- puts h.inspect # >> {:newer=>"b", 3=>"aaa", 4=>"aaaa"}
41
+ puts h.inspect # >> {:newer=>"b", 3=>"aaa", 4=>"aaaa"}
42
+ ```
31
43
 
32
44
  Rufus::Lru::Hash isn't thread-safe, if you need something that is, use Rufus::Lru::SynchronizedHash
33
45
 
34
- require 'rubygems'
35
- require 'rufus-lru'
46
+ ```ruby
47
+ require 'rufus-lru'
48
+
49
+ h = Rufus::Lru::SynchronizedHash.new(3)
50
+
51
+ # ...
52
+ ```
53
+
54
+ It's possible to squeeze LruHash manually:
55
+
56
+ ```ruby
57
+ h = Rufus::Lru::Hash.new(33, :auto_squeeze => false)
58
+ # or
59
+ #h = Rufus::Lru::Hash.new(33)
60
+ #h.auto_squeeze = false
61
+
62
+ # ... values keep accumulating ...
63
+
64
+ # when a squeeze is needed...
65
+ h.squeeze!
66
+ ```
67
+
68
+ LruHash accepts on initialization a ```:on_removal``` option. It can be set to a Symbol, which is then used as the method name to call on the value just removed:
69
+
70
+ ```ruby
71
+ require 'rufus-lru'
72
+
73
+ class ObjectWithDestructor; def clear; puts 'Destructor called'; end; end
74
+
75
+ h = LruHash.new(1, :on_removal => :clear)
76
+
77
+ h[:one] = ObjectWithDestructor.new
78
+ h[:two] = nil # :one is being removed >> "Destructor called"
79
+ ```
80
+
81
+ Or it can be set to a lambda:
82
+
83
+ ```ruby
84
+ require 'rufus-lru'
85
+
86
+ seen = []
87
+ h = Rufus::Lru::Hash.new(
88
+ 1,
89
+ :on_removal => lambda { |val| seen << val.object_id })
90
+
91
+ h[:one] = 'abc'
92
+ h[:two] = 'xyz'
93
+
94
+ # seen ends up with the object_id of the 'abc' String instance...
95
+ ```
96
+
97
+ The value of ```on_removal``` can be set later on.
36
98
 
37
- h = Rufus::Lru::SyncrhonizedHash.new(3)
99
+ ```ruby
100
+ h.on_removal = :destroy
101
+ h.on_removal = lambda { |val| bodycount += 1 if val.is_a?(Martian) }
102
+ ```
38
103
 
39
- # ...
104
+ `auto_squeeze` and `on_removal` were originally contributed by Gleb Kuzmenko.
40
105
 
41
106
 
42
107
  ## dependencies
@@ -65,18 +130,19 @@ irc.freenode.net #ruote
65
130
 
66
131
  http://github.com/jmettraux/rufus-lru
67
132
 
68
- git clone git://github.com/jmettraux/rufus-lru.git
133
+ ```
134
+ git clone git://github.com/jmettraux/rufus-lru.git
135
+ ```
69
136
 
70
137
 
71
138
  ## author
72
139
 
73
- John Mettraux, jmettraux@gmail.com
74
- http://jmettraux.wordpress.com
140
+ John Mettraux, jmettraux@gmail.com, http://lambda.io/jmettraux
75
141
 
76
142
 
77
- ## the rest of Rufus
143
+ ## contributors and help
78
144
 
79
- http://rufus.rubyforge.org
145
+ see [CREDITS.txt](CREDITS.txt)
80
146
 
81
147
 
82
148
  ## license
data/lib/rufus/lru.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2007-2012, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2007-2016, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -19,7 +19,7 @@
19
19
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
  # THE SOFTWARE.
21
21
  #
22
- # "made in Japan"
22
+ # "Made in Japan"
23
23
  #++
24
24
 
25
25
  require 'thread'
@@ -28,7 +28,7 @@ require 'thread'
28
28
  module Rufus
29
29
  module Lru
30
30
 
31
- VERSION = '1.0.5'
31
+ VERSION = '1.0.7'
32
32
 
33
33
  #
34
34
  # A Hash that has a max size. After the maxsize has been reached, the
@@ -48,6 +48,20 @@ module Lru
48
48
  #
49
49
  # puts h.inspect # >> {:newer=>"b", 3=>"aaa", 4=>"aaaa"}
50
50
  #
51
+ # One may want to squeeze hash manually
52
+ #
53
+ # h = LruHash.new(3, true)
54
+ # # or h.squeeze_on_demand=true after h is created
55
+ # .
56
+ # .
57
+ # h.squeeze!
58
+ #
59
+ # If a value has destructor method #clear it may be called upon the
60
+ # key-value removal
61
+ #
62
+ # h = LruHash.new(33, does_not_matter, true)
63
+ # # or h.clear_value_on_removal=true after h is created
64
+ #
51
65
  # Nota bene: this class is not thread-safe. If you need something thread-safe,
52
66
  # use Rufus::Lru::SynchronizedHash.
53
67
  #
@@ -56,28 +70,58 @@ module Lru
56
70
  attr_reader :maxsize
57
71
  attr_reader :lru_keys
58
72
 
73
+ attr_accessor :on_removal
74
+
59
75
  # Initializes a LruHash with a given maxsize.
60
76
  #
61
- def initialize(maxsize)
77
+ # Options:
78
+ #
79
+ # * :auto_squeeze
80
+ # defaults to true
81
+ # * :on_removal
82
+ # accepts false, a symbol or a lambda.
83
+ # * False is the default, values are removed, nothing special happens.
84
+ # * A symbol can be used to point to a method like :clear or :destroy
85
+ # that has to be called on the value just removed
86
+ # * A lambda/proc can be set, it's thus called (and passed the removed
87
+ # value as argument) each time a removal occurs
88
+ #
89
+ def initialize(maxsize, opts={})
62
90
 
63
91
  super()
64
92
 
65
93
  @maxsize = maxsize
66
94
  @lru_keys = []
95
+
96
+ @auto_squeeze = opts.has_key?(:auto_squeeze) ? opts[:auto_squeeze] : true
97
+ @on_removal = opts[:on_removal]
67
98
  end
68
99
 
69
100
  def maxsize=(i)
70
101
 
71
102
  @maxsize = i
72
- remove_lru
103
+ squeeze! if @auto_squeeze
73
104
 
74
105
  i
75
106
  end
76
107
 
108
+ def auto_squeeze=(b)
109
+
110
+ squeeze! if b
111
+ @auto_squeeze = b
112
+ end
113
+
114
+ def auto_squeeze?
115
+
116
+ @auto_squeeze
117
+ end
118
+
77
119
  def clear
78
120
 
79
121
  @lru_keys.clear
80
122
 
123
+ self.each_value { |v| call_on_removal(v) }
124
+
81
125
  super
82
126
  end
83
127
 
@@ -96,7 +140,7 @@ module Lru
96
140
 
97
141
  def []=(key, value)
98
142
 
99
- remove_lru
143
+ remove_lru if @auto_squeeze
100
144
  touch(key)
101
145
 
102
146
  super
@@ -111,9 +155,12 @@ module Lru
111
155
 
112
156
  def delete(key)
113
157
 
158
+ value = super
159
+ call_on_removal(value)
160
+
114
161
  @lru_keys.delete(key)
115
162
 
116
- super
163
+ value
117
164
  end
118
165
 
119
166
  # Returns a regular Hash with the entries in this hash.
@@ -123,6 +170,9 @@ module Lru
123
170
  {}.merge!(self)
124
171
  end
125
172
 
173
+ # public alias to remove_lru
174
+ def squeeze!; remove_lru; end
175
+
126
176
  protected
127
177
 
128
178
  # Puts the key on top of the lru 'stack'.
@@ -143,14 +193,25 @@ module Lru
143
193
  delete(@lru_keys.delete_at(0))
144
194
  end
145
195
  end
196
+
197
+ def call_on_removal(value)
198
+
199
+ if ! @on_removal
200
+ # nothing to do
201
+ elsif @on_removal.is_a?(Symbol)
202
+ value.send(@on_removal)
203
+ else # must be a block
204
+ @on_removal.call(value)
205
+ end
206
+ end
146
207
  end
147
208
 
148
209
  #
149
210
  # A thread-safe version of the lru hash.
150
211
  #
151
- class SynchronizedHash < Hash
212
+ class SynchronizedHash < Rufus::Lru::Hash
152
213
 
153
- def initialize(maxsize)
214
+ def initialize(maxsize, opts={})
154
215
 
155
216
  super
156
217
  @mutex = Mutex.new
@@ -165,6 +226,11 @@ module Lru
165
226
 
166
227
  @mutex.synchronize { super }
167
228
  end
229
+
230
+ def squeeze!
231
+
232
+ @mutex.synchronize { super }
233
+ end
168
234
  end
169
235
  end
170
236
  end
data/rufus-lru.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.email = [ 'jmettraux@gmail.com' ]
13
13
  s.homepage = 'http://github.com/jmettraux/rufus-lru'
14
14
  s.rubyforge_project = 'rufus'
15
+ s.license = 'MIT'
15
16
  s.summary = 'A Hash with a max size, controlled by a LRU mechanism'
16
17
 
17
18
  s.description = %{
@@ -20,15 +21,14 @@ LruHash class, a Hash with a max size, controlled by a LRU mechanism
20
21
 
21
22
  #s.files = `git ls-files`.split("\n")
22
23
  s.files = Dir[
23
- 'Rakefile',
24
- 'lib/**/*.rb', 'spec/**/*.rb', 'test/**/*.rb',
24
+ 'Makefile',
25
+ 'lib/**/*.rb', #'spec/**/*.rb', 'test/**/*.rb',
25
26
  '*.gemspec', '*.txt', '*.rdoc', '*.md'
26
27
  ]
27
28
 
28
29
  #s.add_runtime_dependency 'tzinfo', '>= 0.3.23'
29
30
 
30
- s.add_development_dependency 'rake'
31
- s.add_development_dependency 'rspec', '>= 2.7.0'
31
+ s.add_development_dependency 'rspec', '>= 3.4.0'
32
32
 
33
33
  s.require_path = 'lib'
34
34
  end
metadata CHANGED
@@ -1,39 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-lru
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
5
- prerelease:
4
+ version: 1.0.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - John Mettraux
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-02-28 00:00:00.000000000 +09:00
13
- default_executable:
11
+ date: 2016-05-07 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
- name: rake
17
- requirement: &2153411200 !ruby/object:Gem::Requirement
18
- none: false
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
19
16
  requirements:
20
- - - ! '>='
17
+ - - ">="
21
18
  - !ruby/object:Gem::Version
22
- version: '0'
19
+ version: 3.4.0
23
20
  type: :development
24
21
  prerelease: false
25
- version_requirements: *2153411200
26
- - !ruby/object:Gem::Dependency
27
- name: rspec
28
- requirement: &2153410580 !ruby/object:Gem::Requirement
29
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
30
23
  requirements:
31
- - - ! '>='
24
+ - - ">="
32
25
  - !ruby/object:Gem::Version
33
- version: 2.7.0
34
- type: :development
35
- prerelease: false
36
- version_requirements: *2153410580
26
+ version: 3.4.0
37
27
  description: LruHash class, a Hash with a max size, controlled by a LRU mechanism
38
28
  email:
39
29
  - jmettraux@gmail.com
@@ -41,40 +31,36 @@ executables: []
41
31
  extensions: []
42
32
  extra_rdoc_files: []
43
33
  files:
44
- - Rakefile
45
- - lib/rufus/lru.rb
46
- - lib/rufus-lru.rb
47
- - spec/hash_spec.rb
48
- - spec/lru_hash_spec.rb
49
- - spec/spec_helper.rb
50
- - spec/synchronized_hash_spec.rb
51
- - rufus-lru.gemspec
52
34
  - CHANGELOG.txt
35
+ - CREDITS.txt
53
36
  - LICENSE.txt
37
+ - Makefile
54
38
  - README.md
55
- has_rdoc: true
39
+ - lib/rufus-lru.rb
40
+ - lib/rufus/lru.rb
41
+ - rufus-lru.gemspec
56
42
  homepage: http://github.com/jmettraux/rufus-lru
57
- licenses: []
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
58
46
  post_install_message:
59
47
  rdoc_options: []
60
48
  require_paths:
61
49
  - lib
62
50
  required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
51
  requirements:
65
- - - ! '>='
52
+ - - ">="
66
53
  - !ruby/object:Gem::Version
67
54
  version: '0'
68
55
  required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
56
  requirements:
71
- - - ! '>='
57
+ - - ">="
72
58
  - !ruby/object:Gem::Version
73
59
  version: '0'
74
60
  requirements: []
75
61
  rubyforge_project: rufus
76
- rubygems_version: 1.6.2
62
+ rubygems_version: 2.2.2
77
63
  signing_key:
78
- specification_version: 3
64
+ specification_version: 4
79
65
  summary: A Hash with a max size, controlled by a LRU mechanism
80
66
  test_files: []
data/Rakefile DELETED
@@ -1,87 +0,0 @@
1
-
2
- $:.unshift('.') # 1.9.2
3
-
4
- require 'rubygems'
5
- require 'rubygems/user_interaction' if Gem::RubyGemsVersion == '1.5.0'
6
-
7
- require 'rake'
8
- require 'rake/clean'
9
- #require 'rake/rdoctask'
10
- require 'rdoc/task'
11
-
12
-
13
- #
14
- # clean
15
-
16
- CLEAN.include('pkg', 'rdoc')
17
-
18
-
19
- #
20
- # test / spec
21
-
22
- #task :spec => :check_dependencies do
23
- task :spec do
24
- exec 'rspec spec/'
25
- end
26
- task :test => :spec
27
-
28
- task :default => :spec
29
-
30
-
31
- #
32
- # gem
33
-
34
- GEMSPEC_FILE = Dir['*.gemspec'].first
35
- GEMSPEC = eval(File.read(GEMSPEC_FILE))
36
- GEMSPEC.validate
37
-
38
-
39
- desc %{
40
- builds the gem and places it in pkg/
41
- }
42
- task :build do
43
-
44
- sh "gem build #{GEMSPEC_FILE}"
45
- sh "mkdir pkg" rescue nil
46
- sh "mv #{GEMSPEC.name}-#{GEMSPEC.version}.gem pkg/"
47
- end
48
-
49
- desc %{
50
- builds the gem and pushes it to rubygems.org
51
- }
52
- task :push => :build do
53
-
54
- sh "gem push pkg/#{GEMSPEC.name}-#{GEMSPEC.version}.gem"
55
- end
56
-
57
-
58
- #
59
- # rdoc
60
- #
61
- # make sure to have rdoc 2.5.x to run that
62
-
63
- Rake::RDocTask.new do |rd|
64
-
65
- rd.main = 'README.txt'
66
- rd.rdoc_dir = "rdoc/#{GEMSPEC.name}"
67
-
68
- rd.rdoc_files.include('README.rdoc', 'CHANGELOG.txt', 'lib/**/*.rb')
69
-
70
- rd.title = "#{GEMSPEC.name} #{GEMSPEC.version}"
71
- end
72
-
73
-
74
- #
75
- # upload_rdoc
76
-
77
- desc %{
78
- upload the rdoc to rubyforge
79
- }
80
- task :upload_rdoc => [ :clean, :rdoc ] do
81
-
82
- account = 'jmettraux@rubyforge.org'
83
- webdir = '/var/www/gforge-projects/rufus'
84
-
85
- sh "rsync -azv -e ssh rdoc/#{GEMSPEC.name} #{account}:#{webdir}/"
86
- end
87
-
data/spec/hash_spec.rb DELETED
@@ -1,126 +0,0 @@
1
-
2
- require 'spec_helper'
3
-
4
-
5
- describe Rufus::Lru::Hash do
6
-
7
- let(:hash) { Rufus::Lru::Hash.new(3) }
8
-
9
- context 'like a ::Hash' do
10
-
11
- it 'supports insertion' do
12
-
13
- hash[1] = 2
14
-
15
- hash[1].should == 2
16
- end
17
-
18
- it 'supports deletion' do
19
-
20
- hash[1] = 2
21
-
22
- hash.delete(1).should == 2
23
-
24
- hash.size.should == 0
25
- end
26
- end
27
-
28
- context 'as a LRU Hash' do
29
-
30
- it 'drops entries when the maxsize is reached' do
31
-
32
- 4.times { |i| hash[i] = i }
33
-
34
- hash.size.should == 3
35
- end
36
-
37
- it 're-inserting under a key places the key at the end of the lru_keys' do
38
-
39
- 3.times { |i| hash[i] = i }
40
-
41
- hash[0] = :new
42
-
43
- hash.lru_keys.should == [ 1, 2, 0 ]
44
- end
45
-
46
- it 'removes keys from the lru_keys upon entry deletion' do
47
-
48
- hash[1] = 1
49
- hash.delete(1)
50
-
51
- hash.lru_keys.should == []
52
- end
53
- end
54
-
55
- describe '#lru_keys' do
56
-
57
- it 'returns the keys with the least recently used first' do
58
-
59
- 3.times { |i| hash[i] = i }
60
-
61
- hash.lru_keys.should == [ 0, 1, 2 ]
62
- end
63
- end
64
-
65
- describe '#ordered_keys' do
66
-
67
- it 'is an alias for #lru_keys' do
68
-
69
- 3.times { |i| hash[i] = i }
70
-
71
- hash.lru_keys.should == [ 0, 1, 2 ]
72
- end
73
- end
74
-
75
- describe '#[]' do
76
-
77
- it 'returns nil if there is no value' do
78
-
79
- hash[:x].should == nil
80
- end
81
-
82
- it 'returns false when the value is false' do
83
-
84
- hash[1] = false
85
-
86
- hash[1].should == false
87
- end
88
-
89
- it 'does not modify the LRU list when looking up a non-present key' do
90
-
91
- hash[:x]
92
-
93
- hash.lru_keys.should == []
94
- end
95
-
96
- it 'returns the current value' do
97
-
98
- hash[1] = 2
99
-
100
- hash[1].should == 2
101
- end
102
- end
103
-
104
- describe '#merge!' do
105
-
106
- it 'merges in place' do
107
-
108
- hash.merge!(1 => 1, 2 => 2)
109
-
110
- hash.size.should == 2
111
- hash.lru_keys.sort.should == [ 1, 2 ]
112
- end
113
- end
114
-
115
- describe '#to_h' do
116
-
117
- it 'returns a new hash with the entries of the LRU hash' do
118
-
119
- 4.times { |i| hash[i] = i }
120
-
121
- hash.to_h.class.should == ::Hash
122
- hash.to_h.should == { 1 => 1, 2 => 2, 3 => 3 }
123
- end
124
- end
125
- end
126
-
@@ -1,16 +0,0 @@
1
-
2
- require 'spec_helper'
3
-
4
-
5
- describe LruHash do
6
-
7
- it 'is available from the root namespace' do
8
-
9
- h = LruHash.new(1)
10
-
11
- 2.times { |i| h[i] = i }
12
-
13
- h.size.should == 1
14
- end
15
- end
16
-
data/spec/spec_helper.rb DELETED
@@ -1,21 +0,0 @@
1
-
2
- require 'rufus-lru'
3
-
4
- Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each do |f|
5
- require(f)
6
- end
7
-
8
- RSpec.configure do |config|
9
-
10
- # == Mock Framework
11
- #
12
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
13
- #
14
- # config.mock_with :mocha
15
- # config.mock_with :flexmock
16
- # config.mock_with :rr
17
- config.mock_with :rspec
18
-
19
- #config.include SubalternHelper
20
- end
21
-
@@ -1,23 +0,0 @@
1
-
2
- require 'spec_helper'
3
-
4
-
5
- describe Rufus::Lru::SynchronizedHash do
6
-
7
- # well, you've probably seen better specs...
8
-
9
- let(:hash) { Rufus::Lru::SynchronizedHash.new(3) }
10
-
11
- it 'sports a mutex' do
12
-
13
- hash.instance_variable_get(:@mutex).class.should == Mutex
14
- end
15
-
16
- it 'works' do
17
-
18
- 4.times { |i| hash[i] = i }
19
-
20
- hash.size.should == 3
21
- end
22
- end
23
-