optify-config 1.17.10-arm64-darwin → 1.19.0-arm64-darwin

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: 4d0182bf708b9862e670fc58f918e53f715bea4f6b680166701c527429f5d6d7
4
- data.tar.gz: 8f3ec37f79ffe69ebed0e492dc46529d3a815501e65f8a44fb6109e6a4f9b49e
3
+ metadata.gz: bc273906d7f59c1211be74bf188092c84921658559dd46c1ad56f9d187f3a7a6
4
+ data.tar.gz: 2d5e0d2351bd004f73ee11eda17974861d3b674e539e18fb01a6a6ac1aeedec8
5
5
  SHA512:
6
- metadata.gz: 60b35f9965a6cd0e5e6957b3baa1b639efbc27b63fe0c3e267d309cee996a237b7fabd5039a918c4214d83872252fe1db74e1b30d0d5fd3ceb0514f620440710
7
- data.tar.gz: 7233d519c13dade097a39d2bc0646c4a4a2d24bdee309d91532ebcb6a60fe471176ab316d80a9142aea3897be006f5dabd223ea8cc4547eeb7e96b9c18b78f20
6
+ metadata.gz: 850f0c226b41b4182e5451f10d8fa06de771b73ba9c9da1f2d59c4a2910b6b2205444b0b3e6b0c7e7642f02712dd4490ec3810df5db80e8a1e936228f055af16
7
+ data.tar.gz: 5679d4b2bd8918dbe3cc914d1d6fc24598da9c936a6a6879470fa6854fc04f552849f24eedb93e749aa716007f5fa4cc5b4e0e9a36334882c8446f8e13f23fd4
Binary file
Binary file
Binary file
@@ -0,0 +1,41 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Optify
5
+ # The mode for the cache.
6
+ module CacheMode
7
+ # Non-thread-safe LRU cache.
8
+ # Should be faster than `THREAD_SAFE` for single-threaded applications.
9
+ NOT_THREAD_SAFE = :not_thread_safe #: Symbol
10
+ # Thread-safe LRU cache.
11
+ THREAD_SAFE = :thread_safe #: Symbol
12
+ end
13
+
14
+ # Options for initializing the cache.
15
+ class CacheInitOptions
16
+ #: Integer?
17
+ attr_reader :max_size
18
+
19
+ # A value from `CacheMode`.
20
+ #
21
+ #: Symbol
22
+ attr_reader :mode
23
+
24
+ # Initializes the cache options.
25
+ # Defaults to a non-thread-safe unlimited size cache for backwards compatibility
26
+ # with how this library was originally configured with an unbounded hash as the case.
27
+ # @param mode A value from `CacheMode`.
28
+ #
29
+ #: (
30
+ #| ?max_size: Integer?,
31
+ #| ?mode: Symbol,
32
+ #| ) -> void
33
+ def initialize(
34
+ max_size: nil,
35
+ mode: CacheMode::NOT_THREAD_SAFE
36
+ )
37
+ @max_size = max_size
38
+ @mode = mode
39
+ end
40
+ end
41
+ end
@@ -4,6 +4,7 @@
4
4
  require 'sorbet-runtime'
5
5
 
6
6
  require_relative './base_config'
7
+ require_relative './cache_init_options'
7
8
  require_relative './options_metadata'
8
9
  require_relative './provider_module'
9
10
 
@@ -32,9 +33,9 @@ module Optify
32
33
 
33
34
  # (Optional) Eagerly initializes the cache.
34
35
  # @return [OptionsProvider] `self`.
35
- #: -> OptionsProvider
36
- def init
37
- _init
36
+ #: (?CacheInitOptions?) -> OptionsProvider
37
+ def init(cache_init_options = nil)
38
+ _init(cache_init_options)
38
39
  self
39
40
  end
40
41
  end
@@ -2,11 +2,47 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'json'
5
+ require 'lru_redux'
5
6
  require 'sorbet-runtime'
6
7
 
7
8
  module Optify
8
9
  # @!visibility private
9
10
  module ProviderModule
11
+ #: [T] (LruRedux::Cache | Hash[untyped, untyped], Array[untyped]) { -> T } -> T
12
+ def self._cache_getset(cache, cache_key, &block)
13
+ if cache.is_a? LruRedux::Cache
14
+ cache.getset(cache_key, &block)
15
+ else
16
+ # Plain Hash - use fetch with block and store result
17
+ cache.fetch(cache_key) do
18
+ result = block.call
19
+ cache[cache_key] = result
20
+ end
21
+ end
22
+ end
23
+
24
+ #: (CacheInitOptions?) -> ( Hash[Array[untyped], untyped] | LruRedux::Cache)
25
+ def self._create_cache(cache_init_options)
26
+ # Be backwards compatible with the original implementation of this library.
27
+ return {} if cache_init_options.nil?
28
+
29
+ max_size = cache_init_options.max_size
30
+ mode = cache_init_options.mode
31
+ if max_size.nil?
32
+ Kernel.raise ArgumentError, 'Thread-safe cache is not supported when max_size is nil' if mode == CacheMode::THREAD_SAFE
33
+ {}
34
+ else
35
+ case mode
36
+ when CacheMode::THREAD_SAFE
37
+ LruRedux::ThreadSafeCache.new(max_size)
38
+ when CacheMode::NOT_THREAD_SAFE
39
+ LruRedux::Cache.new(max_size)
40
+ else
41
+ Kernel.raise ArgumentError, "Invalid cache mode: #{mode}"
42
+ end
43
+ end
44
+ end
45
+
10
46
  #: (Array[String] feature_names) -> Array[String]
11
47
  def get_canonical_feature_names(feature_names)
12
48
  # Try to optimize a typical case where there are just a few features.
@@ -55,7 +91,7 @@ module Optify
55
91
  # @return The options.
56
92
  #: [Config] (String, Array[String], Class[Config], ?CacheOptions?, ?Optify::GetOptionsPreferences?) -> Config
57
93
  def _get_options(key, feature_names, config_class, cache_options = nil, preferences = nil)
58
- return get_options_with_cache(key, feature_names, config_class, cache_options, preferences) if cache_options
94
+ return _get_options_with_cache(key, feature_names, config_class, cache_options, preferences) if cache_options
59
95
 
60
96
  unless config_class.respond_to?(:from_hash)
61
97
  Kernel.raise NotImplementedError,
@@ -73,14 +109,8 @@ module Optify
73
109
  .from_hash(hash)
74
110
  end
75
111
 
76
- #: -> void
77
- def _init
78
- @cache = {} #: Hash[untyped, untyped]?
79
- @features_with_metadata = nil #: Hash[String, OptionsMetadata]?
80
- end
81
-
82
112
  #: [Config] (String key, Array[String] feature_names, Class[Config] config_class, Optify::CacheOptions _cache_options, ?Optify::GetOptionsPreferences? preferences) -> Config
83
- def get_options_with_cache(key, feature_names, config_class, _cache_options, preferences = nil)
113
+ def _get_options_with_cache(key, feature_names, config_class, _cache_options, preferences = nil)
84
114
  # Cache directly in Ruby instead of Rust because:
85
115
  # * Avoid any possible conversion overhead.
86
116
  # * Memory management: probably better to do it in Ruby for a Ruby app and avoid memory in Rust.
@@ -100,22 +130,27 @@ module Optify
100
130
  # Features are filtered, so we don't need the constraints in the cache key.
101
131
  are_configurable_strings_enabled = preferences&.are_configurable_strings_enabled? || false
102
132
  cache_key = [key, feature_names, are_configurable_strings_enabled, config_class]
103
- @cache #: as !nil
104
- .fetch(cache_key) do
133
+ ProviderModule._cache_getset(
134
+ @cache, #: as !nil
135
+ cache_key,
136
+ ) do
105
137
  # Handle a cache miss.
106
138
 
107
139
  # We can avoid converting the features names because they're already converted from filtering above, if that was desired.
108
140
  # We don't need the constraints because we filtered the features above.
109
141
  # We already know there are no overrides because we checked above.
110
- preferences = GetOptionsPreferences.new
111
- preferences.skip_feature_name_conversion = true
112
- preferences.enable_configurable_strings if are_configurable_strings_enabled
142
+ cache_miss_preferences = GetOptionsPreferences.new
143
+ cache_miss_preferences.skip_feature_name_conversion = true
144
+ cache_miss_preferences.enable_configurable_strings if are_configurable_strings_enabled
113
145
 
114
- result = _get_options(key, feature_names, config_class, nil, preferences)
115
-
116
- @cache #: as !nil
117
- .[]= cache_key, result
146
+ _get_options(key, feature_names, config_class, nil, cache_miss_preferences)
118
147
  end
119
148
  end
149
+
150
+ #: (?CacheInitOptions?) -> void
151
+ def _init(cache_init_options = nil)
152
+ @cache = ProviderModule._create_cache(cache_init_options) #: ( Hash[untyped, untyped] | LruRedux::Cache)?
153
+ @features_with_metadata = nil #: Hash[String, OptionsMetadata]?
154
+ end
120
155
  end
121
156
  end
@@ -30,9 +30,9 @@ module Optify
30
30
 
31
31
  # (Optional) Eagerly initializes the cache.
32
32
  # @return [OptionsWatcher] `self`.
33
- #: -> OptionsWatcher
34
- def init
35
- _init
33
+ #: (?CacheInitOptions?) -> OptionsWatcher
34
+ def init(cache_init_options = nil)
35
+ _init(cache_init_options)
36
36
  @cache_creation_time = Time.now #: Time?
37
37
  self
38
38
  end
data/rbi/optify.rbi CHANGED
@@ -19,6 +19,37 @@ module Optify
19
19
  class CacheOptions < FromHashable
20
20
  end
21
21
 
22
+ # The mode for the cache.
23
+ module CacheMode
24
+ # Non-thread-safe LRU cache.
25
+ # Should be faster than `THREAD_SAFE` for single-threaded applications.
26
+ NOT_THREAD_SAFE = T.let(:not_thread_safe, Symbol)
27
+ # Thread-safe LRU cache.
28
+ THREAD_SAFE = T.let(:thread_safe, Symbol)
29
+ end
30
+
31
+ # Options for initializing the cache.
32
+ class CacheInitOptions
33
+ sig { returns(T.nilable(Integer)) }
34
+ attr_reader :max_size
35
+
36
+ # A value from `CacheMode`.
37
+ sig { returns(Symbol) }
38
+ attr_reader :mode
39
+
40
+ # Initializes the cache options.
41
+ # Defaults to a non-thread-safe unlimited size cache for backwards compatibility
42
+ # with how this library was originally configured with an unbounded hash as the case.
43
+ # @param mode A value from `CacheMode`.
44
+ sig do
45
+ params(
46
+ max_size: T.nilable(Integer),
47
+ mode: Symbol,
48
+ ).void
49
+ end
50
+ def initialize(max_size: nil, mode: CacheMode::NOT_THREAD_SAFE); end
51
+ end
52
+
22
53
  # Information about a feature.
23
54
  class OptionsMetadata < FromHashable
24
55
  sig { returns(T.nilable(T::Array[String])) }
@@ -188,7 +219,7 @@ module Optify
188
219
  sig do
189
220
  params(
190
221
  feature_names: T::Array[String],
191
- preferences: GetOptionsPreferences
222
+ preferences: GetOptionsPreferences,
192
223
  )
193
224
  .returns(T::Array[String])
194
225
  end
@@ -211,7 +242,7 @@ module Optify
211
242
  feature_names: T::Array[String],
212
243
  config_class: T::Class[T.type_parameter(:Config)],
213
244
  cache_options: T.nilable(CacheOptions),
214
- preferences: T.nilable(Optify::GetOptionsPreferences)
245
+ preferences: T.nilable(Optify::GetOptionsPreferences),
215
246
  )
216
247
  .returns(T.type_parameter(:Config))
217
248
  end
@@ -257,10 +288,18 @@ module Optify
257
288
  end
258
289
  def get_options_json_with_preferences(key, feature_names, preferences); end
259
290
 
291
+ # @param canonical_feature_name [String] A canonical feature name
292
+ # @return Whether the feature has conditions.
293
+ sig { params(canonical_feature_name: String).returns(T::Boolean) }
294
+ def conditions?(canonical_feature_name); end
295
+
260
296
  # (Optional) Eagerly initializes the cache.
261
297
  # @return `self`.
262
- sig { returns(T.self_type) }
263
- def init; end
298
+ sig do
299
+ params(cache_init_options: T.nilable(CacheInitOptions))
300
+ .returns(T.self_type)
301
+ end
302
+ def init(cache_init_options = nil); end
264
303
 
265
304
  private
266
305
 
data/sig/optify.rbs CHANGED
@@ -17,6 +17,22 @@ end
17
17
  class Optify::CacheOptions < FromHashable
18
18
  end
19
19
 
20
+ # The mode for the cache.
21
+ module Optify::CacheMode
22
+ end
23
+
24
+ Optify::Optify::CacheMode::NOT_THREAD_SAFE: Symbol
25
+
26
+ Optify::Optify::CacheMode::THREAD_SAFE: Symbol
27
+
28
+ # Options for initializing the cache.
29
+ class Optify::CacheInitOptions
30
+ # A value from `CacheMode`.
31
+ def initialize: () -> Integer?
32
+ | () -> Symbol
33
+ | (?max_size: Integer? max_size, ?mode: Symbol mode) -> void
34
+ end
35
+
20
36
  # Information about a feature.
21
37
  class Optify::OptionsMetadata < FromHashable
22
38
  def aliases: () -> ::Array[String]?
@@ -159,9 +175,11 @@ module Optify::ProviderModule
159
175
 
160
176
  def get_options_json_with_preferences: (String key, ::Array[String] feature_names, GetOptionsPreferences preferences) -> String
161
177
 
162
- # (Optional) Eagerly initializes the cache.
163
- # @return `self`.
164
- def init: () -> self
178
+ # @param canonical_feature_name [String] A canonical feature name
179
+ # @return Whether the feature has conditions.
180
+ def conditions?: (String canonical_feature_name) -> bool
181
+
182
+ def init: (?CacheInitOptions? cache_init_options) -> self
165
183
 
166
184
  # Map aliases or canonical feature names (perhaps derived from a file names) to the canonical feature names.
167
185
  # Canonical feature names map to themselves.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optify-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.10
4
+ version: 1.19.0
5
5
  platform: arm64-darwin
6
6
  authors:
7
7
  - Justin D. Harris
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-12-01 00:00:00.000000000 Z
11
+ date: 2026-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: optify-from_hash
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.0
19
+ version: 0.2.1
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.2.0
26
+ version: 0.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: sin_lru_redux
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.5.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.5.2
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: sorbet-runtime
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -78,14 +92,14 @@ dependencies:
78
92
  requirements:
79
93
  - - "~>"
80
94
  - !ruby/object:Gem::Version
81
- version: 1.76.1
95
+ version: 1.82.1
82
96
  type: :development
83
97
  prerelease: false
84
98
  version_requirements: !ruby/object:Gem::Requirement
85
99
  requirements:
86
100
  - - "~>"
87
101
  - !ruby/object:Gem::Version
88
- version: 1.76.1
102
+ version: 1.82.1
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: rubocop-sorbet
91
105
  requirement: !ruby/object:Gem::Requirement
@@ -161,6 +175,7 @@ files:
161
175
  - lib/optify_ruby/3.3/optify_ruby.bundle
162
176
  - lib/optify_ruby/3.4/optify_ruby.bundle
163
177
  - lib/optify_ruby/base_config.rb
178
+ - lib/optify_ruby/cache_init_options.rb
164
179
  - lib/optify_ruby/get_options_preferences.rb
165
180
  - lib/optify_ruby/implementation.rb
166
181
  - lib/optify_ruby/options_metadata.rb