core-local 0.0.0 → 0.1.0

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
2
  SHA256:
3
- metadata.gz: 54a183206e86d4ed29ca0019617f33f34bdf7e622b313bc03a858a760a788bcc
4
- data.tar.gz: 0aba2d4d72f4970929498d755bacb46dd60de13d2a9b01fa865bc12f9533769e
3
+ metadata.gz: 6663c3e59d3b4a48e74acbee111551833e7be4fbc00c5ed3f79a965f010242c9
4
+ data.tar.gz: 2e704b5ca8b859abb465026bf01af70c93453c95fb8bcec5f9d1a592deb6a862
5
5
  SHA512:
6
- metadata.gz: dacbd7dbae4b77c044ee9b32f237165785c7ba03993d895b9ef70418f9d541609ad5a6d137346c60e9ad930210fa7e09bd7e19fa18b2eb8630ed139f4e8362aa
7
- data.tar.gz: 1595eeaba26611b1bbd1f2822041732678226029f2a57d5f44551d6bb730b8d9c3d6a1a860d95e1d7c60796b6cbb0c0c896bbe12d9d1830ae3752e26b3ebe760
6
+ metadata.gz: 8a6bdfc3ed3109970a5dec7b3243cd89f8cd57093378018830c89906ba309cf52069b2f50e197e049f2a65230b5d85bcf5361f6c2b949200371a8baeb1921265
7
+ data.tar.gz: 49e0989476ae57aedfd1ecb20b41cf0ae9cdff2431e62f82e22727313279ae3209e9149a0a0eedf8bd66e6fb21cadf0867a81abda18a372c31d4360b485e255b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [v0.1.0](https://github.com/metabahn/corerb/releases/tag/2021-07-07)
2
+
3
+ *released on 2021-07-07*
4
+
5
+ * `chg` [#46](https://github.com/metabahn/corerb/pull/46) Improve performance of localization by removing finalizers ([bryanp](https://github.com/bryanp))
6
+ * `chg` [#43](https://github.com/metabahn/corerb/pull/43) Drop Ruby 2.6 support from core-local ([bryanp](https://github.com/bryanp))
7
+
1
8
  ## [v0.0.0](https://github.com/metabahn/corerb/releases/tag/2021-02-10)
2
9
 
3
10
  *released on 2021-02-10*
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Local
5
- VERSION = "0.0.0"
5
+ VERSION = "0.1.0"
6
6
 
7
7
  def self.version
8
8
  VERSION
data/lib/is/localized.rb CHANGED
@@ -12,24 +12,33 @@ module Is
12
12
 
13
13
  # [public] Localize `value` for `key` in the current thread or fiber.
14
14
  #
15
+ # Be aware that you can easily introduce memory leaks into your program if you aren't careful to clean up localized
16
+ # state. There's two ways to approach this:
17
+ #
18
+ # 1. Pass a block to `localize`. The value will be localized and cleaned up after being yielded to the block.
19
+ #
20
+ # 2. Call `unlocalize` manually when you no longer need the localized value.
21
+ #
15
22
  def localize(key, value)
16
23
  key = localized_key(key)
17
24
 
18
25
  Core::Local::Store[key] = value
19
26
 
20
- unless frozen?
21
- # Cleanup keys in the localized object when the object itself goes away.
22
- #
23
- ObjectSpace.define_finalizer(self, Core::Local::Store.cleanup(key))
27
+ if block_given?
28
+ begin
29
+ yield value
30
+ ensure
31
+ Core::Local::Store.delete(key)
32
+ end
33
+ else
34
+ value
24
35
  end
25
36
  end
26
37
 
27
38
  # [public] Returns the localized value for `key`, or `fallback`.
28
39
  #
29
40
  def localized(key, fallback = nil)
30
- key = localized_key(key)
31
-
32
- Core::Local::Store.fetch(key, fallback)
41
+ Core::Local::Store.fetch(localized_key(key), fallback)
33
42
  end
34
43
 
35
44
  # [public] Deletes the localized value for `key`.
@@ -39,7 +48,11 @@ module Is
39
48
  end
40
49
 
41
50
  private def localized_key(name)
42
- :"__corerb_localized_#{object_id}_#{name}"
51
+ "#{localized_key_prefix}_#{name}"
52
+ end
53
+
54
+ private def localized_key_prefix
55
+ @__localized_key_prefix ||= "__corerb_localized_#{object_id}"
43
56
  end
44
57
  end
45
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: core-local
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-10 00:00:00.000000000 Z
11
+ date: 2021-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-extension
@@ -62,14 +62,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
62
  requirements:
63
63
  - - ">="
64
64
  - !ruby/object:Gem::Version
65
- version: 2.5.0
65
+ version: '2.7'
66
66
  required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubygems_version: 3.2.4
72
+ rubygems_version: 3.2.15
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: Manage thread-local program state.