core-local 0.1.1 → 0.2.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: 7738c287512d5856b20261ebb71498a81370d3117e822239226111e461033aff
4
- data.tar.gz: c1e11995c1449d4a88734e4b275c11d4df11657b8864a431c1e971235c25fe0a
3
+ metadata.gz: 1cbb44371e75ca683b34bde49d8e10ae841580e5e09706e58fbb9c7c41a34903
4
+ data.tar.gz: 1ea04b80e6abb2c54619a808d207187d90b1032918d8f241516bbd4f24a9e54f
5
5
  SHA512:
6
- metadata.gz: 293baad0b168eb9e3040e127ca139f06fa79a96c23e75d56cbbae36e55f7069a638e2f734fe0c547d37cdbbb2ee760c02fde47d59bc18e422491bb2ffa07f334
7
- data.tar.gz: af2f168bfb4c1e94ba09ed8d962ee25b38633cd86e2d4212726ce6d8225caf4c8f27ef2d8199fd7a3bb648d93aba130822b8771e6891ae822e0651188efa05c9
6
+ metadata.gz: cb5c76aeacf5f29b441e42c4302ca3254ce7109de4b14c5b92607b651eb9caa0ff977ec0ee41d08cbad61cc0afd452fa3b37ac3e07f801241ddcac381f60f2fe
7
+ data.tar.gz: c9de924afeae9afbde335484be912207679f5e6d21b8c104a74b5daeeb9974dd2728a16674163203d55b1b537f8ae431b52ab7eef1f5b379fa876d80058565d1
data/CHANGELOG.md CHANGED
@@ -1,14 +1,27 @@
1
- ## [v0.1.0](https://github.com/metabahn/corerb/releases/tag/2021-07-07)
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)
9
+
10
+ *released on 2021-11-02*
11
+
12
+ * `chg` [#97](https://github.com/bryanp/corerb/pull/97) Designate internal state with leading and trailing double underscores ([bryanp](https://github.com/bryanp))
13
+
14
+ ## [v0.1.0](https://github.com/bryanp/corerb/releases/tag/2021-07-07)
2
15
 
3
16
  *released on 2021-07-07*
4
17
 
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))
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))
7
20
 
8
- ## [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)
9
22
 
10
23
  *released on 2021-02-10*
11
24
 
12
- * `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))
13
26
 
14
27
 
@@ -7,13 +7,13 @@ 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
14
14
 
15
15
  def initialize
16
- @key = :"__corerb_localized_state_#{object_id}"
16
+ @key = :"__corerb_localized_state_#{object_id}__"
17
17
  end
18
18
 
19
19
  # [public] Returns a proc that, when called, deletes the key from the global store.
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Local
5
- VERSION = "0.1.1"
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.1
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-07-15 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.15
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