weak 0.2.0 → 0.2.1

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
2
  SHA256:
3
- metadata.gz: 86165785c0d1874c5c54d7a72c3b703f5a21832cf0df8ffa917b4793dc40c502
4
- data.tar.gz: a02c81a859c4f887181a2e33a124d6584a987d40cde92770fd1d6953a836f10d
3
+ metadata.gz: 1495109d765259effd2efb1f7d97c7ad7e71e060ecb1d8f8f6cd6386e3a4d93c
4
+ data.tar.gz: 73be12838b3bdb16f45215dd9b07152e798d62130ca0bdfbca999b57a21ae25d
5
5
  SHA512:
6
- metadata.gz: 60d9a3259f88cd37a001b60fdf5247a856d1c637a54d0085712b347ab9b4c0dda330e8cabe69ead1bdf8193fdb70d8a0f7b419ea407afdcbea0b8e659331473c
7
- data.tar.gz: b2dbc7c76ee9fd24d1a06df292e4683f5f5eb1a1b7a2d9db6ab653e691e818d3d6b3975589e020c47daede1b50ab48a4c417830af1c7b4cac12a9e2b61dc47f1
6
+ metadata.gz: 35c2aa978606c8c1bd1c83838e9eb418eba8e4bada89936675fcb82c6a6a24304da7e34a56b38cf2bab42fd0b682efcf2577c2fecb4fd2c7fb02344869ab3cfd
7
+ data.tar.gz: 47e6c245cfe310e9ad7b538028cac0e36531b3c856ac3ec6efbb66126ac5c51f26dbecc03a516eca9598f8c81f02de5e26a51c435cc2f40a86a7d39ff2253793
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.2.1] - 2025-12-27
6
+
7
+ - Fix typos in code documentation
8
+ - Ignore some unnecessary methods defined on some `Set` implementations in `set_spec`
9
+ - Run specs on JRuby 10 in Github Actions
10
+ - Retry TruffleRuby rspec runs on Github Actions to avoid random failures due to flakey GC.
11
+ - Extract UNDEFINED to its own file and require it where used.
12
+ - Add more details about the gem version in `Weak::Version`
13
+ - Handle object cycles in `pretty_print`.
14
+
5
15
  ## [0.2.0] - 2025-04-09
6
16
 
7
17
  - Add `Weak::Map#delete_if`
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Weak
2
2
 
3
3
  [![gem version badge](https://badge.fury.io/rb/weak.svg)](https://rubygems.org/gems/weak)
4
- [![CI status badge](https://github.com/meineerde/weak/actions/workflows/ci.yml/badge.svg)](https://github.com/meineerde/weak/actions/workflows/ci.yml)
5
- [![Coverage Status](https://coveralls.io/repos/github/meineerde/weak/badge.svg?branch=main)](https://coveralls.io/github/meineerde/weak?branch=main)
4
+ [![github repo badge](https://img.shields.io/badge/github-repo-blue?logo=github)](https://github.com/meineerde/weak)
6
5
 
7
6
  Weak is a Ruby library which implements collections of unordered values without strong object references.
8
7
 
@@ -38,11 +37,11 @@ set
38
37
  `Weak::Map` behaves similar to a `Hash` or an `ObjectSpace::WeakMap` in Ruby (aka. MRI, aka. YARV).
39
38
  Both keys and values are weak references, allowing either of them to be garbage collected. If either the key or the value of a pair is garbage collected, the entire pair will be removed from the `Weak::Map`.
40
39
 
41
- Compared to the `Set` class however, there are a few differences:
40
+ Compared to the `Hash` class however, there are a few differences:
42
41
 
43
42
  - Key and value references are weak, allowing each key-value pair to be garbage collected unless there is a strong reference to boith the key and the value somewhere else.
44
43
  - We do not necessarily retain the order of elements as they are inserted into the `Weak::Map`. You should not rely on a specific order.
45
- - Map membership is governed by object identity of the key rather than by using the `hash` and `eql?` methods of the elements. A `Weak::Map` thus works similat to a `Hash` marked as [compare_by_identity](https://docs.ruby-lang.org/en/3.4/Hash.html#method-i-compare_by_identity).
44
+ - Map membership is governed by object identity of the key rather than by using its `hash` and `eql?` methods. A `Weak::Map` thus works similar to a `Hash` marked as [compare_by_identity](https://docs.ruby-lang.org/en/3.4/Hash.html#method-i-compare_by_identity).
46
45
  - You can freely change both keys and values added to the `Weak::Map`.
47
46
 
48
47
  ```ruby
@@ -64,7 +63,7 @@ map
64
63
  Please refer to the documentation at:
65
64
 
66
65
  - [📘 Documentation](https://www.rubydoc.info/gems/weak)
67
- - [💥 Development Documentation](https://www.rubydoc.info/github/meineerde/weak/main) of the [main branch](https://github.com/meineerde/weak/tree/main)
66
+ - [💥 Development Documentation](https://www.rubydoc.info/github/meineerde/weak) of the [main branch](https://github.com/meineerde/weak/tree/main)
68
67
 
69
68
  > [!WARNING]
70
69
  > The Weak collections are not inherently thread-safe. When accessing a collection from multiple threads or fibers, you MUST use a mutex or another locking mechanism.
@@ -213,6 +212,9 @@ end
213
212
 
214
213
  ## Development
215
214
 
215
+ [![CI status badge](https://github.com/meineerde/weak/actions/workflows/ci.yml/badge.svg)](https://github.com/meineerde/weak/actions/workflows/ci.yml)
216
+ [![Coverage Status](https://coveralls.io/repos/github/meineerde/weak/badge.svg?branch=main)](https://coveralls.io/github/meineerde/weak?branch=main)
217
+
216
218
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
217
219
 
218
220
  [![code style: standard badge](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/standardrb/standard)
@@ -225,7 +227,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/meinee
225
227
 
226
228
  ## License
227
229
 
228
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
230
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
229
231
 
230
232
  ## Code of Conduct
231
233
 
@@ -34,9 +34,9 @@ module Weak
34
34
  private
35
35
 
36
36
  # This method is called during {#_get}. It generally needs to be
37
- # overwritten in a "sub"-mdule to automatically cleanup any internal data.
38
- # The implemented `auto_prune` method should quickly check if a prune is
39
- # necessary and then either call the `prune` method or return.
37
+ # overwritten in a "sub"-module to automatically cleanup any internal
38
+ # data. The implemented `auto_prune` method should quickly check if a
39
+ # prune is necessary and then either call the `prune` method or return.
40
40
  #
41
41
  # @return [void]
42
42
  def auto_prune
@@ -8,6 +8,7 @@
8
8
  require "set"
9
9
 
10
10
  require "weak/map/abstract_strong_keys"
11
+ require "weak/undefined"
11
12
 
12
13
  ##
13
14
  module Weak
@@ -8,6 +8,7 @@
8
8
  require "set"
9
9
 
10
10
  require "weak/map/abstract_strong_keys"
11
+ require "weak/undefined"
11
12
 
12
13
  ##
13
14
  module Weak
@@ -6,6 +6,7 @@
6
6
  # of the MIT license. See the LICENSE.txt file for details.
7
7
 
8
8
  require "weak/map/deletable"
9
+ require "weak/undefined"
9
10
 
10
11
  ##
11
12
  module Weak
@@ -5,6 +5,8 @@
5
5
  # This software may be modified and distributed under the terms
6
6
  # of the MIT license. See the LICENSE.txt file for details.
7
7
 
8
+ require "weak/undefined"
9
+
8
10
  ##
9
11
  module Weak
10
12
  class Map
data/lib/weak/map.rb CHANGED
@@ -5,10 +5,11 @@
5
5
  # This software may be modified and distributed under the terms
6
6
  # of the MIT license. See the LICENSE.txt file for details.
7
7
 
8
- require_relative "map/weak_keys_with_delete"
9
- require_relative "map/weak_keys"
10
- require_relative "map/strong_keys"
11
- require_relative "map/strong_secondary_keys"
8
+ require "weak/map/weak_keys_with_delete"
9
+ require "weak/map/weak_keys"
10
+ require "weak/map/strong_keys"
11
+ require "weak/map/strong_secondary_keys"
12
+ require "weak/undefined"
12
13
 
13
14
  ##
14
15
  module Weak
@@ -486,8 +487,8 @@ module Weak
486
487
 
487
488
  object_ids << object_id
488
489
  begin
489
- elements = to_a.sort_by! { |k, _v| k.__id__ }.to_h.inspect[1..-2]
490
- "#<#{self.class} {#{elements}}>"
490
+ elements = to_a.sort_by! { |k, _v| k.__id__ }.to_h
491
+ "#<#{self.class} #{elements}>"
491
492
  ensure
492
493
  object_ids.pop
493
494
  end
@@ -590,6 +591,11 @@ module Weak
590
591
  end
591
592
  end
592
593
 
594
+ # @!visibility private
595
+ def pretty_print_cycle(pp)
596
+ pp.text "#<#{self.class} {#{"..." unless empty?}}>"
597
+ end
598
+
593
599
  # Deletes every key-value pair from `self` for which the given block
594
600
  # evaluates to a truethy value.
595
601
  #
data/lib/weak/set.rb CHANGED
@@ -561,7 +561,7 @@ module Weak
561
561
 
562
562
  # @!visibility private
563
563
  def pretty_print_cycle(pp)
564
- pp.text "#<#{self.class} {#{empty? ? "" : "..."}}>"
564
+ pp.text "#<#{self.class} {#{"..." unless empty?}}>"
565
565
  end
566
566
 
567
567
  # @param other [Weak::Set] a weak set
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) Holger Just
4
+ #
5
+ # This software may be modified and distributed under the terms
6
+ # of the MIT license. See the LICENSE.txt file for details.
7
+
8
+ require "singleton"
9
+
10
+ ##
11
+ module Weak
12
+ # A class for the {UNDEFINED} object. Being a singleton, there will only be
13
+ # exactly one object of this class: the {UNDEFINED} object.
14
+ #
15
+ # @private
16
+ class UndefinedClass
17
+ include Singleton
18
+
19
+ def initialize
20
+ freeze
21
+ end
22
+
23
+ # @return [String] the string `"UNDEFINED"`
24
+ def to_s
25
+ "UNDEFINED"
26
+ end
27
+ alias_method :inspect, :to_s
28
+ end
29
+
30
+ # The {UNDEFINED} object can be used as the default value for method arguments
31
+ # to distinguish it from `nil`.
32
+ #
33
+ # @see https://holgerjust.de/2016/detecting-default-arguments-in-ruby/#special-default-value
34
+ UNDEFINED = UndefinedClass.instance
35
+ end
data/lib/weak/version.rb CHANGED
@@ -7,8 +7,36 @@
7
7
 
8
8
  ##
9
9
  module Weak
10
- # The {Weak} version as a `Gem::Version` string. We follow semantic
11
- # versioning.
12
- # @see https://semver.org/
13
- VERSION = "0.2.0"
10
+ # Version information about {Weak}}. We follow semantic versioning.
11
+ module Version
12
+ # MAJOR version. It is incremented after incompatible API changes
13
+ MAJOR = 0
14
+ # MINOR version. It is incremented after adding functionality in a
15
+ # backwards-compatible manner
16
+ MINOR = 2
17
+ # PATCH version. It is incremented when making backwards-compatible
18
+ # bug-fixes.
19
+ PATCH = 1
20
+ # PRERELEASE suffix. Set to a alphanumeric string on any pre-release
21
+ # versions like beta or RC releases; `nil` on regular releases
22
+ PRERELEASE = nil
23
+
24
+ # The {Weak} version as a `Gem::Version` string. We follow semantic
25
+ # versioning.
26
+ # @see https://semver.org/
27
+ STRING = [MAJOR, MINOR, PATCH, PRERELEASE].compact.join(".").freeze
28
+
29
+ # @return [Gem::Version] the {Weak} version as a `Gem::Version` object
30
+ def self.gem_version
31
+ Gem::Version.new STRING
32
+ end
33
+
34
+ # @return [String] the Weak version as a `Gem::Version` string
35
+ def self.to_s
36
+ STRING
37
+ end
38
+ end
39
+
40
+ # (see Version::STRING)
41
+ VERSION = Weak::Version::STRING
14
42
  end
data/lib/weak.rb CHANGED
@@ -5,8 +5,6 @@
5
5
  # This software may be modified and distributed under the terms
6
6
  # of the MIT license. See the LICENSE.txt file for details.
7
7
 
8
- require "singleton"
9
-
10
8
  require_relative "weak/version"
11
9
  require_relative "weak/map"
12
10
  require_relative "weak/set"
@@ -19,27 +17,4 @@ require_relative "weak/set"
19
17
  # elements can be garbage collected and silently removed from the collection
20
18
  # unless they are still referenced from some other live object.
21
19
  module Weak
22
- # A class for the {UNDEFINED} object. Being a singleton, there will only be
23
- # exactly one object of this class: the {UNDEFINED} object.
24
- #
25
- # @private
26
- class UndefinedClass
27
- include Singleton
28
-
29
- def initialize
30
- freeze
31
- end
32
-
33
- # @return [String] the string `"UNDEFINED"`
34
- def to_s
35
- "UNDEFINED"
36
- end
37
- alias_method :inspect, :to_s
38
- end
39
-
40
- # The {UNDEFINED} object can be used as the default value for method arguments
41
- # to distinguish it from `nil`.
42
- #
43
- # @see https://holgerjust.de/2016/detecting-default-arguments-in-ruby/#special-default-value
44
- UNDEFINED = UndefinedClass.instance
45
20
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Holger Just
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-09 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: |
13
13
  The Weak library provides a Weak::Set class to store an unordered list of
@@ -36,6 +36,7 @@ files:
36
36
  - lib/weak/set/strong_secondary_keys.rb
37
37
  - lib/weak/set/weak_keys.rb
38
38
  - lib/weak/set/weak_keys_with_delete.rb
39
+ - lib/weak/undefined.rb
39
40
  - lib/weak/version.rb
40
41
  homepage: https://github.com/meineerde/weak
41
42
  licenses:
@@ -45,7 +46,7 @@ metadata:
45
46
  homepage_uri: https://github.com/meineerde/weak
46
47
  source_code_uri: https://github.com/meineerde/weak
47
48
  changelog_uri: https://github.com/meineerde/weak/blob/main/CHANGELOG.md
48
- documentation_uri: https://www.rubydoc.info/gems/weak/0.2.0
49
+ documentation_uri: https://www.rubydoc.info/gems/weak/0.2.1
49
50
  rdoc_options: []
50
51
  require_paths:
51
52
  - lib
@@ -60,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
61
  - !ruby/object:Gem::Version
61
62
  version: '0'
62
63
  requirements: []
63
- rubygems_version: 3.6.3
64
+ rubygems_version: 4.0.3
64
65
  specification_version: 4
65
66
  summary: Tools to handle collections of weakly-referenced values
66
67
  test_files: []