core-local 0.1.2 → 0.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
2
  SHA256:
3
- metadata.gz: 3833c0a7562ca1fa2a2a5d278cf5978003da75f418e2e95523a5c160156edfbb
4
- data.tar.gz: bd2708472e0410a3e93ab4ced300afce6da45e716022bdde102ec1dda0f4ade8
3
+ metadata.gz: 1cbb44371e75ca683b34bde49d8e10ae841580e5e09706e58fbb9c7c41a34903
4
+ data.tar.gz: 1ea04b80e6abb2c54619a808d207187d90b1032918d8f241516bbd4f24a9e54f
5
5
  SHA512:
6
- metadata.gz: 9418411bba915f4597a9f05bf4dfc24d8a5d66cf06ea9b8417ecea0f0ca760eed8e6642cd438457384e8dd9f68d61e3595274a9f453ecb04a21d63b7209b22cb
7
- data.tar.gz: 37c59aa28256ffb3e34c193024194b18d2fc93a1c090b67a04a27b2ef27eb193235618eadc4d2a42d0a96887a3affd2a811f76824607504c03e45eefbe2646c8
6
+ metadata.gz: cb5c76aeacf5f29b441e42c4302ca3254ce7109de4b14c5b92607b651eb9caa0ff977ec0ee41d08cbad61cc0afd452fa3b37ac3e07f801241ddcac381f60f2fe
7
+ data.tar.gz: c9de924afeae9afbde335484be912207679f5e6d21b8c104a74b5daeeb9974dd2728a16674163203d55b1b537f8ae431b52ab7eef1f5b379fa876d80058565d1
data/CHANGELOG.md CHANGED
@@ -1,20 +1,27 @@
1
- ## [v0.1.2](https://github.com/metabahn/corerb/releases/tag/2021-11-02)
1
+ ## [v0.2.0](https://github.com/bryanp/corerb/releases/tag/2023-12-24)
2
+
3
+ *released on 2023-12-24*
4
+
5
+ * `dep` [#143](https://github.com/bryanp/corerb/pull/143) Deprecate `Is::*` and `Refine::*` namespaces ([bryanp](https://github.com/bryanp))
6
+ * `dep` [#135](https://github.com/bryanp/corerb/pull/135) Remove Ruby 2 support ([bryanp](https://github.com/bryanp))
7
+
8
+ ## [v0.1.2](https://github.com/bryanp/corerb/releases/tag/2021-11-02)
2
9
 
3
10
  *released on 2021-11-02*
4
11
 
5
- * `chg` [#97](https://github.com/metabahn/corerb/pull/97) Designate internal state with leading and trailing double underscores ([bryanp](https://github.com/bryanp))
12
+ * `chg` [#97](https://github.com/bryanp/corerb/pull/97) Designate internal state with leading and trailing double underscores ([bryanp](https://github.com/bryanp))
6
13
 
7
- ## [v0.1.0](https://github.com/metabahn/corerb/releases/tag/2021-07-07)
14
+ ## [v0.1.0](https://github.com/bryanp/corerb/releases/tag/2021-07-07)
8
15
 
9
16
  *released on 2021-07-07*
10
17
 
11
- * `chg` [#46](https://github.com/metabahn/corerb/pull/46) Improve performance of localization by removing finalizers ([bryanp](https://github.com/bryanp))
12
- * `chg` [#43](https://github.com/metabahn/corerb/pull/43) Drop Ruby 2.6 support from core-local ([bryanp](https://github.com/bryanp))
18
+ * `chg` [#46](https://github.com/bryanp/corerb/pull/46) Improve performance of localization by removing finalizers ([bryanp](https://github.com/bryanp))
19
+ * `chg` [#43](https://github.com/bryanp/corerb/pull/43) Drop Ruby 2.6 support from core-local ([bryanp](https://github.com/bryanp))
13
20
 
14
- ## [v0.0.0](https://github.com/metabahn/corerb/releases/tag/2021-02-10)
21
+ ## [v0.0.0](https://github.com/bryanp/corerb/releases/tag/2021-02-10)
15
22
 
16
23
  *released on 2021-02-10*
17
24
 
18
- * `add` [#5](https://github.com/metabahn/corerb/pull/5) Initial core-local behavior ([bryanp](https://github.com/bryanp))
25
+ * `add` [#5](https://github.com/bryanp/corerb/pull/5) Initial core-local behavior ([bryanp](https://github.com/bryanp))
19
26
 
20
27
 
@@ -7,7 +7,7 @@ module Core
7
7
  # [public] Simple key/value store, localized to a thread or fiber.
8
8
  #
9
9
  class Store
10
- include Is::Global
10
+ include Core::Global
11
11
 
12
12
  extend Forwardable
13
13
  def_delegators :state, :[], :[]=, :fetch, :delete, :clear, :count
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Local
5
- VERSION = "0.1.2"
5
+ VERSION = "0.2.0"
6
6
 
7
7
  def self.version
8
8
  VERSION
data/lib/core/local.rb CHANGED
@@ -1,10 +1,59 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "core/extension"
4
+
3
5
  module Core
6
+ # [public] Manage thread-local program state for an object.
7
+ #
4
8
  module Local
5
9
  require_relative "local/store"
6
10
  require_relative "local/version"
11
+
12
+ extend Core::Extension
13
+
14
+ # [public] Localize `value` for `key` in the current thread or fiber.
15
+ #
16
+ # Be aware that you can easily introduce memory leaks into your program if you aren't careful to clean up localized
17
+ # state. There's two ways to approach this:
18
+ #
19
+ # 1. Pass a block to `localize`. The value will be localized and cleaned up after being yielded to the block.
20
+ #
21
+ # 2. Call `unlocalize` manually when you no longer need the localized value.
22
+ #
23
+ def localize(key, value)
24
+ key = localized_key(key)
25
+
26
+ Core::Local::Store[key] = value
27
+
28
+ if block_given?
29
+ begin
30
+ yield value
31
+ ensure
32
+ Core::Local::Store.delete(key)
33
+ end
34
+ else
35
+ value
36
+ end
37
+ end
38
+
39
+ # [public] Returns the localized value for `key`, or `fallback`.
40
+ #
41
+ def localized(key, fallback = nil)
42
+ Core::Local::Store.fetch(localized_key(key), fallback)
43
+ end
44
+
45
+ # [public] Deletes the localized value for `key`.
46
+ #
47
+ def unlocalize(key)
48
+ Core::Local::Store.delete(localized_key(key))
49
+ end
50
+
51
+ private def localized_key(name)
52
+ "#{localized_key_prefix}_#{name}"
53
+ end
54
+
55
+ private def localized_key_prefix
56
+ @__localized_key_prefix__ ||= "__corerb_localized_#{object_id}__"
57
+ end
7
58
  end
8
59
  end
9
-
10
- require_relative "../is/localized"
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.1.2
4
+ version: 0.2.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-11-02 00:00:00.000000000 Z
11
+ date: 2023-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-extension
@@ -16,30 +16,30 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.3'
19
+ version: '0.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.3'
26
+ version: '0.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: core-global
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.0'
33
+ version: '0.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.0'
40
+ version: '0.3'
41
41
  description: Manage thread-local program state.
42
- email: bryan@metabahn.com
42
+ email: bryan@bryanp.org
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
@@ -49,8 +49,7 @@ files:
49
49
  - lib/core/local.rb
50
50
  - lib/core/local/store.rb
51
51
  - lib/core/local/version.rb
52
- - lib/is/localized.rb
53
- homepage: https://github.com/metabahn/corerb/
52
+ homepage: https://github.com/bryanp/corerb/
54
53
  licenses:
55
54
  - MPL-2.0
56
55
  metadata: {}
@@ -62,14 +61,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
61
  requirements:
63
62
  - - ">="
64
63
  - !ruby/object:Gem::Version
65
- version: '2.7'
64
+ version: '3.0'
66
65
  required_rubygems_version: !ruby/object:Gem::Requirement
67
66
  requirements:
68
67
  - - ">="
69
68
  - !ruby/object:Gem::Version
70
69
  version: '0'
71
70
  requirements: []
72
- rubygems_version: 3.2.22
71
+ rubygems_version: 3.5.1
73
72
  signing_key:
74
73
  specification_version: 4
75
74
  summary: Manage thread-local program state.
data/lib/is/localized.rb DELETED
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "core/extension"
4
-
5
- require_relative "../core/local/store"
6
-
7
- module Is
8
- # [public] Manage thread-local program state for an object.
9
- #
10
- module Localized
11
- extend Is::Extension
12
-
13
- # [public] Localize `value` for `key` in the current thread or fiber.
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
- #
22
- def localize(key, value)
23
- key = localized_key(key)
24
-
25
- Core::Local::Store[key] = value
26
-
27
- if block_given?
28
- begin
29
- yield value
30
- ensure
31
- Core::Local::Store.delete(key)
32
- end
33
- else
34
- value
35
- end
36
- end
37
-
38
- # [public] Returns the localized value for `key`, or `fallback`.
39
- #
40
- def localized(key, fallback = nil)
41
- Core::Local::Store.fetch(localized_key(key), fallback)
42
- end
43
-
44
- # [public] Deletes the localized value for `key`.
45
- #
46
- def unlocalize(key)
47
- Core::Local::Store.delete(localized_key(key))
48
- end
49
-
50
- private def localized_key(name)
51
- "#{localized_key_prefix}_#{name}"
52
- end
53
-
54
- private def localized_key_prefix
55
- @__localized_key_prefix__ ||= "__corerb_localized_#{object_id}__"
56
- end
57
- end
58
- end