nova-api 1.9.0 → 1.10.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 +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +1 -1
- data/README.md +10 -0
- data/lib/nova/api/utils/base_struct.rb +1 -0
- data/lib/nova/api/version.rb +1 -1
- data/lib/nova/api.rb +40 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c0fbc5096804dd54c1d97774f9635c99a0bfa43f91327817d345c10443861eda
|
|
4
|
+
data.tar.gz: 1d571800c7d52f1ccc9a05c5b33fd6d5765292d1fa71b854208f4a4ba9ae20ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9354aea92ede4f23fe371f1dccfc67041e75015160141d0cc8e3b223b4a289480654bb15d4fb049bdb0298b8dd7395d030b4735961b53fcabddc8a77ab26e157
|
|
7
|
+
data.tar.gz: 472d308fbb65a803f6be0b0989d8c79f57887b1d2a8636731443eefc40637848e69890b5376b084ac60c8c800fa9c47641e474441861898ede7516d23db4b1aa
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.10.0] - 2026-11-09
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `Nova::API.with_configuration`, which overrides configuration attributes for the current thread during a block
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- `Nova::API.configure` called outside the main thread now changes a copy private to that thread, instead of the configuration shared by the whole process
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- `NameError` for `Forwardable` when requiring the gem in an environment that had not loaded it yet
|
|
21
|
+
|
|
8
22
|
## [1.9.0] - 2026-11-09
|
|
9
23
|
|
|
10
24
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -36,6 +36,16 @@ Nova::API.configure do |config|
|
|
|
36
36
|
end
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
Calling ```configure``` on the main thread, as an initializer does at boot, sets the configuration for the whole process. Calling it on any other thread, such as a Puma request thread, only affects that thread.
|
|
40
|
+
|
|
41
|
+
Web servers reuse their threads, so anything set with ```configure``` during a request is still there for the next request served by that thread. For multi-tenant applications, prefer ```with_configuration```, which only applies during the block:
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
44
|
+
around_action do |_controller, action|
|
|
45
|
+
Nova::API.with_configuration(subdomain: current_tenant.subdomain, api_key: current_tenant.api_key) { action.call }
|
|
46
|
+
end
|
|
47
|
+
```
|
|
48
|
+
|
|
39
49
|
After that you can start using the resources either by:
|
|
40
50
|
|
|
41
51
|
- Instantiating a new ```Nova::API::Client``` object;
|
data/lib/nova/api/version.rb
CHANGED
data/lib/nova/api.rb
CHANGED
|
@@ -49,13 +49,51 @@ module Nova
|
|
|
49
49
|
class MissingIdError < Error; end
|
|
50
50
|
class EndpointNotConfiguredError < Error; end
|
|
51
51
|
|
|
52
|
+
THREAD_CONFIGURATION_KEY = :nova_api_configuration
|
|
53
|
+
private_constant :THREAD_CONFIGURATION_KEY
|
|
54
|
+
|
|
55
|
+
@configuration = Configuration.new
|
|
56
|
+
|
|
52
57
|
class << self
|
|
58
|
+
# The configuration in effect for the current thread: its own, when it has
|
|
59
|
+
# one, or else the one shared by the whole process.
|
|
53
60
|
def configuration
|
|
54
|
-
@configuration
|
|
61
|
+
thread_configuration || @configuration
|
|
55
62
|
end
|
|
56
63
|
|
|
64
|
+
# On the main thread (application boot) this changes the configuration
|
|
65
|
+
# shared by the whole process. On any other thread (a Puma request, for
|
|
66
|
+
# instance) it changes a copy private to that thread.
|
|
57
67
|
def configure
|
|
58
|
-
yield(configuration)
|
|
68
|
+
yield(Thread.current == Thread.main ? configuration : own_thread_configuration)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Runs the block with the given attributes overridden for the current
|
|
72
|
+
# thread only, restoring the previous configuration afterwards. Prefer this
|
|
73
|
+
# for per-request configuration, since nothing is left on the pooled thread.
|
|
74
|
+
def with_configuration(**overrides)
|
|
75
|
+
previous = thread_configuration
|
|
76
|
+
scoped = configuration.dup
|
|
77
|
+
overrides.each { |attribute, value| scoped.public_send("#{attribute}=", value) }
|
|
78
|
+
self.thread_configuration = scoped
|
|
79
|
+
|
|
80
|
+
yield
|
|
81
|
+
ensure
|
|
82
|
+
self.thread_configuration = previous
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
private
|
|
86
|
+
|
|
87
|
+
def own_thread_configuration
|
|
88
|
+
thread_configuration || (self.thread_configuration = @configuration.dup)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def thread_configuration
|
|
92
|
+
Thread.current.thread_variable_get(THREAD_CONFIGURATION_KEY)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def thread_configuration=(value)
|
|
96
|
+
Thread.current.thread_variable_set(THREAD_CONFIGURATION_KEY, value)
|
|
59
97
|
end
|
|
60
98
|
end
|
|
61
99
|
|