fiber-storage 0.0.1 → 0.1.1

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: 77ad72476d9a5209661f380069bcfc6d4478cc7e3a7e7c7eadea738051bdbf9d
4
- data.tar.gz: 0bf1132f9b6902487c93fd66c9bec0ec2c50485a15a5f7fe5e2b8907142e1a25
3
+ metadata.gz: 2a489930803579f4332fbb2bd4d8f67747023459161948c33876af91bb205827
4
+ data.tar.gz: 2c74c2b760ef22020bd883fe9a32095e710fe46314bd8683f006572422d3ee31
5
5
  SHA512:
6
- metadata.gz: 17578725c8cd96ba921ee24273f9a9134a391102b9f1cecbba8ce66983d93663d00a3bffe0565c72b365767d43fac31a329c166ade9a5c14461c1491e19759d1
7
- data.tar.gz: b9ea2b14c0bc99ced0b169f659f8b110154819ad83656a4015d316aa62c93c1af006eed54944c7ab95e3fedc8abb24e5ce975b00288b75f430e5f5cfde0a526e
6
+ metadata.gz: fc1af54cde665a185c288c1e367181677bd3e12274917ad4b8e969ff34e2b1a02a3d568063764e725ec7ea8a25582cfa37427a682382990d3724f72d2e71f4ee
7
+ data.tar.gz: 6deae713309f42988f28ca2ef09fe88bbe5fbcc06ee3c32029e3e78b8ea8590018c075df0d0a3de7ab59e2e38e149a44ec43c2ff6e419fb78f90635eabb88430
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022, by Samuel Williams.
4
+ # Copyright, 2022-2023, by Samuel Williams.
5
5
 
6
6
  require 'fiber'
7
7
 
8
8
  class Fiber
9
9
  module Storage
10
- VERSION = "0.0.1"
10
+ VERSION = "0.1.1"
11
11
  end
12
12
  end
data/lib/fiber/storage.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022, by Samuel Williams.
4
+ # Copyright, 2022-2023, by Samuel Williams.
5
5
 
6
6
  require 'fiber'
7
7
 
@@ -11,38 +11,73 @@ class Fiber
11
11
  case storage
12
12
  when true
13
13
  @storage = Fiber.current.storage
14
- when false
15
- @storage = Fiber.current.__storage__
16
14
  else
15
+ raise TypeError, "Storage must be a hash!" unless storage.is_a?(Hash)
16
+
17
17
  @storage = storage
18
18
  end
19
19
 
20
20
  super(*arguments, **options, &block)
21
21
  end
22
22
 
23
+ # Set the storage associated with this fiber, clearing any previous storage.
23
24
  def storage=(hash)
24
25
  @storage = hash.dup
25
26
  end
26
27
 
28
+ # The storage associated with this fiber.
27
29
  def storage
28
30
  @storage.dup
29
31
  end
30
32
 
31
33
  def __storage__
32
- @storage
34
+ @storage ||= {}
33
35
  end
34
36
  end
35
37
 
36
38
  unless Fiber.current.respond_to?(:storage)
37
- warn "Fiber#storage is running in compatibility mode."
39
+ warn "Fiber#storage is missing and being monkey-patched."
38
40
  prepend Storage
39
41
 
42
+ # Get a value from the current fiber's storage.
40
43
  def self.[] key
44
+ raise TypeError, "Key must be symbol!" unless key.is_a?(Symbol)
45
+
41
46
  self.current.__storage__[key]
42
47
  end
43
48
 
49
+ # Set a value in the current fiber's storage.
44
50
  def self.[]= key, value
51
+ raise TypeError, "Key must be symbol!" unless key.is_a?(Symbol)
52
+
45
53
  self.current.__storage__[key] = value
46
54
  end
55
+ else
56
+ def self.__borked_keys__
57
+ !Fiber.new do
58
+ key = :"#{self.object_id}.key"
59
+ Fiber[key] = true
60
+ Fiber[key]
61
+ end.resume
62
+ end
63
+
64
+ if __borked_keys__
65
+ module FixBorkedKeys
66
+ def [](key)
67
+ raise TypeError, "Key must be symbol!" unless key.is_a?(Symbol)
68
+
69
+ super(eval(key.inspect))
70
+ end
71
+
72
+ def []=(key, value)
73
+ raise TypeError, "Key must be symbol!" unless key.is_a?(Symbol)
74
+
75
+ super(eval(key.inspect), value)
76
+ end
77
+ end
78
+
79
+ warn "Fiber#storage has borked keys and is being monkey-patched."
80
+ singleton_class.prepend FixBorkedKeys
81
+ end
47
82
  end
48
83
  end
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2022, by Samuel Williams.
3
+ Copyright, 2022-2023, by Samuel Williams.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Fiber::Storage
2
2
 
3
- This gem provides a shim for `Fiber.[]`, `Fiber.[]=`, `Fiber#storage`, `Fiber#storage=`.
3
+ This gem provides a shim for `Fiber.[]`, `Fiber.[]=`, `Fiber#storage`, `Fiber#storage=`, which was introduced in Ruby 3.2.
4
+
5
+ [![Development Status](https://github.com/ioquatix/fiber-storage/workflows/Test/badge.svg)](https://github.com/ioquatix/fiber-storage/actions?workflow=Test)
4
6
 
5
7
  ## Motivation
6
8
 
@@ -8,21 +10,6 @@ Ruby 3.2 introduces inheritable fiber storage for per-request or per-operation s
8
10
 
9
11
  Notably, it does not support inheritance across threads or lazy Enumerator. This is a limitation of the shim implementation.
10
12
 
11
- ## Installation
12
-
13
- Add the gem to your project:
14
-
15
- ```shell
16
- $ bundle add fiber-storage
17
- ```
18
-
19
13
  ## Usage
20
14
 
21
- ```ruby
22
- require 'fiber/storage'
23
-
24
- Fiber[:x] = 10
25
- Fiber.new do
26
- Fiber[:x] # => 10
27
- end.resume
28
- ```
15
+ See the [project documentation](https://ioquatix.github.io/fiber-storage).
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fiber-storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -37,50 +37,8 @@ cert_chain:
37
37
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
38
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
39
  -----END CERTIFICATE-----
40
- date: 2022-12-02 00:00:00.000000000 Z
41
- dependencies:
42
- - !ruby/object:Gem::Dependency
43
- name: bundler
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
- - !ruby/object:Gem::Dependency
57
- name: covered
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- - !ruby/object:Gem::Dependency
71
- name: sus
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: '0'
40
+ date: 2024-05-19 00:00:00.000000000 Z
41
+ dependencies: []
84
42
  description:
85
43
  email:
86
44
  executables: []
@@ -91,10 +49,13 @@ files:
91
49
  - lib/fiber/storage/version.rb
92
50
  - license.md
93
51
  - readme.md
94
- homepage: https://github.com/socketry/fiber-storage
52
+ homepage: https://github.com/ioquatix/fiber-storage
95
53
  licenses:
96
54
  - MIT
97
- metadata: {}
55
+ metadata:
56
+ documentation_uri: https://ioquatix.github.io/fiber-storage/
57
+ funding_uri: https://github.com/sponsors/ioquatix/
58
+ source_code_uri: https://github.com/ioquatix/fiber-storage.git
98
59
  post_install_message:
99
60
  rdoc_options: []
100
61
  require_paths:
@@ -103,14 +64,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
64
  requirements:
104
65
  - - ">="
105
66
  - !ruby/object:Gem::Version
106
- version: 2.7.0
67
+ version: '2.7'
107
68
  required_rubygems_version: !ruby/object:Gem::Requirement
108
69
  requirements:
109
70
  - - ">="
110
71
  - !ruby/object:Gem::Version
111
72
  version: '0'
112
73
  requirements: []
113
- rubygems_version: 3.3.7
74
+ rubygems_version: 3.5.3
114
75
  signing_key:
115
76
  specification_version: 4
116
77
  summary: Provides a compatibility shim for fiber storage.
metadata.gz.sig CHANGED
Binary file