optify-config 1.18.0-x86_64-linux → 1.19.0-x86_64-linux
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/lib/optify_ruby/3.2/optify_ruby.so +0 -0
- data/lib/optify_ruby/3.3/optify_ruby.so +0 -0
- data/lib/optify_ruby/3.4/optify_ruby.so +0 -0
- data/lib/optify_ruby/cache_init_options.rb +41 -0
- data/lib/optify_ruby/implementation.rb +4 -3
- data/lib/optify_ruby/provider_module.rb +52 -17
- data/lib/optify_ruby/watcher_implementation.rb +3 -3
- data/rbi/optify.rbi +38 -4
- data/sig/optify.rbs +17 -3
- metadata +19 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b817d3396d7397e472fda368222f22fbb4b13978d8657bae7fdff1e71d0724c1
|
|
4
|
+
data.tar.gz: ec60a48b7ff9ed847e0e0c25c4678b52177f561b2d7949d0ac17a8da2c85f886
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8babfb061313a6660ae431dfd7e3bc2a931cc206f1aa2818bd1cc0a6edc327989c4c89604d403084042a81f036a2b7fb7f7faecadf75e19d006b4678fa558355
|
|
7
|
+
data.tar.gz: cb11f31d9d504deacd854ab86d04ba48d7a19e7db33c70f2df4b964adaf5b43ee56d2194902b6397802ac733909640402e2fc363f66ec725525bd148917a5bf2
|
|
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
|
|
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
|
|
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
|
-
|
|
104
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
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
|
|
@@ -264,8 +295,11 @@ module Optify
|
|
|
264
295
|
|
|
265
296
|
# (Optional) Eagerly initializes the cache.
|
|
266
297
|
# @return `self`.
|
|
267
|
-
sig
|
|
268
|
-
|
|
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
|
|
269
303
|
|
|
270
304
|
private
|
|
271
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]?
|
|
@@ -163,9 +179,7 @@ module Optify::ProviderModule
|
|
|
163
179
|
# @return Whether the feature has conditions.
|
|
164
180
|
def conditions?: (String canonical_feature_name) -> bool
|
|
165
181
|
|
|
166
|
-
|
|
167
|
-
# @return `self`.
|
|
168
|
-
def init: () -> self
|
|
182
|
+
def init: (?CacheInitOptions? cache_init_options) -> self
|
|
169
183
|
|
|
170
184
|
# Map aliases or canonical feature names (perhaps derived from a file names) to the canonical feature names.
|
|
171
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.
|
|
4
|
+
version: 1.19.0
|
|
5
5
|
platform: x86_64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- Justin D. Harris
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
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
|
|
@@ -24,6 +24,20 @@ dependencies:
|
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
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.
|
|
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.
|
|
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.so
|
|
162
176
|
- lib/optify_ruby/3.4/optify_ruby.so
|
|
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
|