rufus-lru 1.0.7 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.txt +7 -0
  3. data/lib/rufus/lru.rb +11 -12
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d40c5ee89890b41593bb60c367782f88f3161f19
4
- data.tar.gz: cc2e44a4052e047fcc8d19023e07f0c48697dba4
3
+ metadata.gz: fadaf6eb162f59102384bfd7ab2644dd4a92a3ac
4
+ data.tar.gz: 1125e6912736d8d81bd4cc3783a562d9b7b70269
5
5
  SHA512:
6
- metadata.gz: 74bcdcd1aac5ce64c9df134a13c83835e749ed019d374c9915ea200229588e2f749f4031a93f9a7a9b2c01b16639586adf0b655d84f8f0971ccd9259d7827aa0
7
- data.tar.gz: 12fb4a8406a3026f9957e9f48770d9aa5a8bf3d369ee04c6bde4b6411fadffcf06c85ad78bcf0cd54d4b0dc6f3acd1da9218bca144de39d42da4e6f07eee81ee
6
+ metadata.gz: 951c82d35ed2797a5b6fcb3a4ba9674cdb08879a0af9dee8cdf367a64171eb2f5868b362f85f37a4d623694a2777ce5e624f4aeba32cc9fac72f55f63ce7d336
7
+ data.tar.gz: cf87c4d1f79aba92cc4a696ec21de9bff71ab5723b2d92def56be6d16aa123811fb461581c586a114e000da820659b3e44bd6d47cecab83e40ca670fb78d9ce8
@@ -2,6 +2,13 @@
2
2
  = rufus-lru CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-lru - 1.1.0 released 2016/05/09
6
+
7
+ - respect maxsize (3 is 3, not 2) (hence the 1.1.x)
8
+ - rename #remove_lru to #do_squeeze!
9
+ - raise ArgumentError if maxsize < 0
10
+
11
+
5
12
  == rufus-lru - 1.0.7 released 2016/05/07
6
13
 
7
14
  - modernized spec/
@@ -28,7 +28,7 @@ require 'thread'
28
28
  module Rufus
29
29
  module Lru
30
30
 
31
- VERSION = '1.0.7'
31
+ VERSION = '1.1.0'
32
32
 
33
33
  #
34
34
  # A Hash that has a max size. After the maxsize has been reached, the
@@ -88,6 +88,8 @@ module Lru
88
88
  #
89
89
  def initialize(maxsize, opts={})
90
90
 
91
+ fail ArgumentError.new("maxsize must be >= 0") if maxsize < 0
92
+
91
93
  super()
92
94
 
93
95
  @maxsize = maxsize
@@ -107,8 +109,7 @@ module Lru
107
109
 
108
110
  def auto_squeeze=(b)
109
111
 
110
- squeeze! if b
111
- @auto_squeeze = b
112
+ squeeze! if (@auto_squeeze = b)
112
113
  end
113
114
 
114
115
  def auto_squeeze?
@@ -140,10 +141,9 @@ module Lru
140
141
 
141
142
  def []=(key, value)
142
143
 
143
- remove_lru if @auto_squeeze
144
- touch(key)
145
-
146
144
  super
145
+ touch(key)
146
+ do_squeeze! if @auto_squeeze
147
147
  end
148
148
 
149
149
  def merge!(hash)
@@ -170,8 +170,7 @@ module Lru
170
170
  {}.merge!(self)
171
171
  end
172
172
 
173
- # public alias to remove_lru
174
- def squeeze!; remove_lru; end
173
+ def squeeze!; do_squeeze!; end
175
174
 
176
175
  protected
177
176
 
@@ -187,10 +186,10 @@ module Lru
187
186
  # Makes sure that the hash fits its maxsize. If not, will remove
188
187
  # the least recently used items.
189
188
  #
190
- def remove_lru
189
+ def do_squeeze!
191
190
 
192
- while size >= @maxsize
193
- delete(@lru_keys.delete_at(0))
191
+ while size > @maxsize
192
+ delete(@lru_keys.shift)
194
193
  end
195
194
  end
196
195
 
@@ -229,7 +228,7 @@ module Lru
229
228
 
230
229
  def squeeze!
231
230
 
232
- @mutex.synchronize { super }
231
+ @mutex.synchronize { do_squeeze! }
233
232
  end
234
233
  end
235
234
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-lru
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-07 00:00:00.000000000 Z
11
+ date: 2016-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec