hashery 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 55701ae88fe04551d5cec0f05916443eb5caa507
4
- data.tar.gz: 3c7f559ddff06a73a17e88582405df23c70503ca
2
+ SHA256:
3
+ metadata.gz: 15088e45c4e270297f602666aa98fc94820a86b8625e313620826896f3568d94
4
+ data.tar.gz: '09ec7ae967d0652a909aed5425b362002e983e9e0680bd76883128e7e81d32d4'
5
5
  SHA512:
6
- metadata.gz: 4f9d36a7748e170982b068b858638cd03f7d1bea42732ee8935c5436e92a409e1ddc694dca8722ad73593d0deab3e53f6150a9903dca074ec266c9cd74f022de
7
- data.tar.gz: 4a6150c4cb3532273b7397deff56e73c46e4c9b1f7f519bb90196986c94090265fa32674b63271366944f4d79b51640336265fe388a10847ebe35a414fb4cd28
6
+ metadata.gz: cd8bf0d32c1c5b8c301beda12612679bae8d3e76a7ede77a70a9a6984d8b4096cb766076e8814d85ae819686b1b6807d89a5027c29bbcd7e2eac80f4a9b802f0
7
+ data.tar.gz: e6ffe274fb89be2e26e9a21e715d118ec795d3c4bcc4bad82218c5c2cebb8f6c677b645fa07a3ac37a9171e24471d996eb26213469ce5d77b5a2938451227184
data/HISTORY.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # RELEASE HISTORY
2
2
 
3
+ ## 2.2.0 / 2026-11-16
4
+
5
+ This release concentrates on LRUHash, by far the most used part of the
6
+ Hashery. Its public API is unchanged, but it has been reimplemented on top
7
+ of Ruby's ordered Hash instead of a linked list of nodes, which makes it
8
+ about twice as fast, and a number of bugs have been fixed. It also
9
+ modernizes the project: Ruby 2.7 or newer is now required, the gem is
10
+ built from a plain gemspec, and CI runs on GitHub Actions.
11
+
12
+ Changes:
13
+
14
+ * LRUHash is about 2x faster, using Ruby's ordered Hash internally.
15
+ * Fix LRUHash#dup and #clone, which shared state with the original.
16
+ * Fix LRUHash#inspect and #to_s, which showed keys and values with #to_s
17
+ and failed under frozen string literals.
18
+ * LRUHash#keys and #values now list most recently used first, like #each.
19
+ * LRUHash#fetch accepts a default argument and its KeyError names the key.
20
+ * LRUHash#delete accepts a block for missing keys, like Hash#delete.
21
+ * LRUHash#delete_if returns an Enumerator when called without a block.
22
+ * Add LRUHash#length.
23
+ * Fix IniHash.new with a Hash, and so IniHash.text and .write_to_file.
24
+ * Fix IniHash.write_to_file with a comment (used String#each).
25
+ * Fix `require 'hashery/static_hash'` on its own.
26
+ * Prepare for frozen string literals and fix warnings under `ruby -w`.
27
+ * Require Ruby 2.7 or newer.
28
+ * Replace Indexer metadata (.index, Index.yml) with hashery.gemspec.
29
+ * Replace Travis CI with GitHub Actions.
30
+
31
+ ## 2.1.2 / 2016-05-02
32
+
33
+ Minor release fixes a test for KeyHash. And that's it.
34
+
35
+ Changes:
36
+
37
+ * Fix initialize test for KeyHash class.
38
+
39
+
3
40
  ## 2.1.1 / 2013-08-21
4
41
 
5
42
  This minor release clarifies the licensing. The entire library is now
data/README.md CHANGED
@@ -1,15 +1,12 @@
1
1
  # Hashery
2
2
 
3
- [![Gem Version](http://img.shields.io/gem/v/hashery.svg?style=flat)](http://rubygems.org/gem/hashery)
4
- [![Build Status](http://img.shields.io/travis/rubyworks/hashery.svg?style=flat)](http://travis-ci.org/rubyworks/hashery)
5
- [![Fork Me](http://img.shields.io/badge/scm-github-blue.svg?style=flat)](http://github.com/rubyworks/hashery)
6
- [![Report Issue](http://img.shields.io/github/issues/rubyworks/hashery.svg?style=flat)](http://github.com/rubyworks/hashery/issues)
7
- [![Gittip](http://img.shields.io/badge/gittip-$1/wk-green.svg?style=flat)](https://www.gittip.com/rubyworksorg/)
3
+ [![Gem Version](https://img.shields.io/gem/v/hashery.svg?style=flat)](https://rubygems.org/gems/hashery)
4
+ [![CI](https://github.com/rubyworks/hashery/actions/workflows/ci.yml/badge.svg)](https://github.com/rubyworks/hashery/actions/workflows/ci.yml)
5
+ [![Report Issue](https://img.shields.io/github/issues/rubyworks/hashery.svg?style=flat)](https://github.com/rubyworks/hashery/issues)
8
6
 
9
- [Homepage](http://rubyworks.github.com/hashery) ·
10
- [Development](http://github.com/rubyworks/hashery) ·
11
- [Report Issue](http://github.com/rubyworks/hashery/issues) ·
12
- [Chat](https://kiwiirc.com/client/irc.freenode.net/?nick=user1|?#rubyworks)
7
+ [Homepage](https://rubyworks.github.io/hashery) ·
8
+ [Development](https://github.com/rubyworks/hashery) ·
9
+ [Report Issue](https://github.com/rubyworks/hashery/issues)
13
10
 
14
11
 
15
12
  ## Description
@@ -19,11 +16,10 @@ of Hash-like classes. To better support this collection
19
16
  of libraries it was deemed prudent to create a new project
20
17
  specifically for them. Hence the *Facets Hashery*.
21
18
 
22
- Included in this collection are the widely used OrderedHash,
23
- the related but more featured Dictionary class, a number
24
- of _open_ classes similar to the standard OpenStruct,
25
- some variations of the standard Hash class and a few
26
- other yummy morsels.
19
+ Included in this collection are the widely used LRUHash,
20
+ the auto-sorting Dictionary class, a number of _open_ classes
21
+ similar to the standard OpenStruct, some variations of the
22
+ standard Hash class and a few other yummy morsels.
27
23
 
28
24
 
29
25
  ## Usage
@@ -33,6 +29,36 @@ included in this collection and read the demo documents which give
33
29
  examples of almost all features.
34
30
 
35
31
 
32
+ ### LRUHash
33
+
34
+ `Hashery::LRUHash` is a size-limited Hash that evicts the least recently
35
+ used entry when full. It can be required on its own:
36
+
37
+ ```ruby
38
+ require 'hashery/lru_hash'
39
+
40
+ cache = Hashery::LRUHash.new(2)
41
+ cache[:a] = 1
42
+ cache[:b] = 2
43
+ cache[:a] # reading :a makes it the most recently used
44
+ cache[:c] = 3 # full, so :b, the least recently used, is evicted
45
+
46
+ cache.keys # => [:c, :a] (most recently used first)
47
+ cache.fetch(:b, 0) # => 0
48
+ ```
49
+
50
+ Reading with `#[]`, `#fetch`, `#assoc`, `#rassoc`, `#key` or `#values_at`
51
+ marks an entry as most recently used; `#has_key?`, `#has_value?` and iteration
52
+ do not. Like `Hash.new`, it takes an optional default value or block. Set
53
+ `#release_proc` to be told about every entry that leaves the cache:
54
+
55
+ ```ruby
56
+ cache.release_proc = ->(key, value) { value.close }
57
+ ```
58
+
59
+ An LRUHash is not thread-safe; guard it with a `Mutex` if threads share it.
60
+
61
+
36
62
  ### Core Extensions
37
63
 
38
64
  Hashery adds four core extensions of Ruby's Hash class: `#retrieve`,
@@ -45,17 +71,15 @@ sorely missing for Ruby itself, which is why they are provided here.
45
71
 
46
72
  ## Installation
47
73
 
48
- To install with RubyGems simply open a console and type:
74
+ Hashery requires Ruby 2.7 or newer. To install with RubyGems simply
75
+ open a console and type:
49
76
 
50
- $ sudo gem install hashery
77
+ $ gem install hashery
51
78
 
52
79
  Or add it as a dependency to your project's Gemfile:
53
80
 
54
81
  gem "hashery"
55
82
 
56
- Tarball packages are available for manual site installations
57
- via [Ruby Setup](http://rubyworks.github.com/setup).
58
-
59
83
 
60
84
  ## Authors
61
85
 
@@ -77,41 +101,34 @@ Well *git* in there!
77
101
 
78
102
  ### Communicating
79
103
 
80
- The project is hosted on Github so the easiest means of communication
81
- is via the [Issues](http://github.com/rubyworks/hashery/issues) page.
82
- For more direct communication you can try the **#rubyworks** IRC channel
83
- on **irc.freenode.net**.
84
-
85
-     [![IRC](https://kiwiirc.com/buttons/irc.freenode.net/rubyworks.png)](https://kiwiirc.com/client/irc.freenode.net/?nick=user1|?#rubyworks)
104
+ The project is hosted on GitHub so the easiest means of communication
105
+ is via the [Issues](https://github.com/rubyworks/hashery/issues) page.
86
106
 
87
107
  ### Testing
88
108
 
89
- Hashery uses [QED](http://rubyworks.github.com/qed) and
90
- [Lemon](http://rubyworks.github.com/lemon) test frameworks.
109
+ Hashery uses [QED](https://rubyworks.github.io/qed) and
110
+ [Lemon](https://rubyworks.github.io/lemon) test frameworks.
91
111
  The QED framework to create well tested high-level documentation.
92
- Run the QED specs via:
112
+ Lemon is used to create low-level unit tests. Install the development
113
+ dependencies and run both via:
114
+
115
+ $ bundle install
116
+ $ bundle exec rake
93
117
 
94
- $ qed -Ilib demo/
118
+ Or run the QED specs on their own via:
95
119
 
96
- Lemon is used to create low-level unit tests. Run these via the Rubytest:
120
+ $ bundle exec qed -Ilib demo/
97
121
 
98
- $ rubytest -Ilib -Itest test/
122
+ And the Lemon unit tests via Rubytest:
123
+
124
+ $ bundle exec rubytest -Ilib -Itest test/
99
125
 
100
126
  ### Patches
101
127
 
102
- Hashery's repository is hosted on [GitHub](http://github.com/rubyworks/hashery).
128
+ Hashery's repository is hosted on [GitHub](https://github.com/rubyworks/hashery).
103
129
  If you'd like to offer up a fix or feature, fork the repo and submit a pull
104
130
  request (preferably in a topic branch). I assume you have heard
105
- all the talk about proper [practices](https://github.com/rubyworks/rubyworks.github.com/wiki/GitHub-Best-Pactices),
106
- so I won't bug you with it yet again.
107
-
108
- ### Donations
109
-
110
- Yes, we FOSS programmers need to eat too! ;-) No seriously, any help you can
111
- offer goes a long way toward continued development of Rubyworks projects,
112
- including Hashery. Hop over to our [Gittips](https://www.gittip.com/rubyworksorg/)
113
- page, or see the upper right-hand corner on the [Rubyworks](http://rubyworks.github.com) homepage.
114
- Thanks!
131
+ all the talk about proper practices, so I won't bug you with it yet again.
115
132
 
116
133
 
117
134
  ## Copyrights
@@ -9,7 +9,7 @@ class Hash
9
9
  # Returns a `Hash`.
10
10
  #
11
11
  def self.create(initial_hash={}, &block)
12
- o = new &block
12
+ o = new(&block)
13
13
  o.update(initial_hash)
14
14
  o
15
15
  end
@@ -324,7 +324,7 @@ module Hashery
324
324
  #
325
325
  def replace(other)
326
326
  super cast(other)
327
- end
327
+ end
328
328
 
329
329
  #
330
330
  # Get the values at.
@@ -334,7 +334,7 @@ module Hashery
334
334
  # Returns `Array` of values.
335
335
  #
336
336
  def values_at(*keys)
337
- super *keys.map{ |key| cast_key(key) }
337
+ super(*keys.map{ |key| cast_key(key) })
338
338
  end
339
339
 
340
340
  # Convert CRUDHash to regular Hash.
@@ -177,7 +177,7 @@ module Hashery
177
177
  unless @fuzz_test
178
178
  @fuzz_test = Object.new
179
179
  @fuzz_test.instance_variable_set(:'@fuzzies', fuzzies)
180
- method = "
180
+ method = +"
181
181
  def match(str)
182
182
  case str\n
183
183
  "
@@ -115,7 +115,7 @@ module Hashery
115
115
  @path = path if String === path
116
116
  @inihash = (Hash === path ? path.dup : {})
117
117
 
118
- if load or ( load.nil? and FileTest.readable_real? @path )
118
+ if load or ( load.nil? and @path and FileTest.readable_real? @path )
119
119
  restore()
120
120
  end
121
121
  end
@@ -185,7 +185,7 @@ module Hashery
185
185
  # Returns a string in the ini file format.
186
186
  #
187
187
  def to_s
188
- str = ""
188
+ str = +""
189
189
  inihash.each do |key, value|
190
190
  if value.is_a? Hash
191
191
  str << "[#{key.to_s}]\n"
@@ -259,7 +259,7 @@ module Hashery
259
259
  # Returns a `String` with the comments from the beginning of the INI file.
260
260
  #
261
261
  def self.read_comment_from_file(path)
262
- comment = ""
262
+ comment = +""
263
263
 
264
264
  IO.foreach(path) do |line|
265
265
  line.strip!
@@ -289,7 +289,7 @@ module Hashery
289
289
  File.open(path, "w") { |file|
290
290
 
291
291
  unless comment.nil?
292
- comment.each do |line|
292
+ comment.each_line do |line|
293
293
  file << "# #{line}"
294
294
  end
295
295
  end
@@ -216,7 +216,7 @@ module Hashery
216
216
  #
217
217
  def node_delete(n)
218
218
  node_join(n.prev_node,n.next_node)
219
- v = n.value
219
+ n.value
220
220
  end
221
221
 
222
222
  #