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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa39e814bbceecbe8191606e74224febce92a84c0f1104f3c9c4d4df02b6f2e9
4
- data.tar.gz: 86907f861fe768cf51f646dfca498f19a30d1dc0c8514f9d4434ae7f8b89a4c2
3
+ metadata.gz: c0fbc5096804dd54c1d97774f9635c99a0bfa43f91327817d345c10443861eda
4
+ data.tar.gz: 1d571800c7d52f1ccc9a05c5b33fd6d5765292d1fa71b854208f4a4ba9ae20ac
5
5
  SHA512:
6
- metadata.gz: '0391d5f88122b8e7dfabc1386939f40c7b57c5d9928626a5db73da4080018b4cb339df0ac21c885a35002253fafdd6ebcb5e23e6df12e16fae0dbce0570d6e64'
7
- data.tar.gz: 62f754ce3115dc2d1b90cd7a9d9ab47cd0f4c443f1100e548b3fcab345f97558045d873c2ffaebb7277fa152c66157182b33feddaabc739127a60115da9746a1
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nova-api (1.9.0)
4
+ nova-api (1.10.0)
5
5
  dry-struct (~> 1.6)
6
6
  dry-types (~> 1.7)
7
7
  httparty (~> 0.1)
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;
@@ -1,5 +1,6 @@
1
1
  require 'dry-struct'
2
2
  require 'dry-types'
3
+ require 'forwardable'
3
4
 
4
5
  module Nova
5
6
  module API
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nova
4
4
  module API
5
- VERSION = '1.9.0'
5
+ VERSION = '1.10.0'
6
6
  end
7
7
  end
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 ||= Configuration.new
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nova-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coyô Software