optify-config 1.18.0 → 1.20.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/ext/optify_ruby/Cargo.toml +1 -1
- data/ext/optify_ruby/src/lib.rs +42 -19
- 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 +42 -4
- data/sig/optify.rbs +21 -3
- metadata +18 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b9dd88296e3b768722678600aeda7d5e990d675b5165c7a0e2f878af54bc33fb
|
|
4
|
+
data.tar.gz: b28522bf1042b9f5c3ce12759118d61a670539dbdd1b44ee03c07560204a2c96
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 21d05d3bf852a27f1503118c3b1514180b3d1e60822549ebac31d231b5d6f250fe53829dc033e155c4d9ed3506f76c4c775233abe8159307272323f41315904b
|
|
7
|
+
data.tar.gz: fb6ada9be0fd33096a73d2b3536857f9d2ed7b6bd5be62cd34bb1ff51d0097027474bb82005c13e25eb898f4ef9c3aed60ee9671a2e7f18c27d8dcc75aa8a700
|
data/ext/optify_ruby/Cargo.toml
CHANGED
data/ext/optify_ruby/src/lib.rs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
use magnus::{
|
|
1
|
+
use magnus::{
|
|
2
|
+
exception::ExceptionClass, function, method, prelude::*, wrap, Object, RModule, Ruby,
|
|
3
|
+
Value as RbValue,
|
|
4
|
+
};
|
|
2
5
|
use optify::builder::OptionsProviderBuilder;
|
|
3
6
|
use optify::builder::OptionsRegistryBuilder;
|
|
4
7
|
use optify::builder::OptionsWatcherBuilder;
|
|
@@ -13,6 +16,24 @@ use crate::preferences::MutGetOptionsPreferences;
|
|
|
13
16
|
|
|
14
17
|
mod preferences;
|
|
15
18
|
|
|
19
|
+
const UNKNOWN_FEATURE_PATTERN: &str = "is not a known feature.";
|
|
20
|
+
|
|
21
|
+
fn get_unknown_feature_error(ruby: &Ruby) -> Result<ExceptionClass, magnus::Error> {
|
|
22
|
+
let module: RModule = ruby.class_object().const_get("Optify")?;
|
|
23
|
+
module.const_get("UnknownFeatureError")
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fn map_feature_error(ruby: &Ruby, error: String) -> magnus::Error {
|
|
27
|
+
if error.contains(UNKNOWN_FEATURE_PATTERN) {
|
|
28
|
+
match get_unknown_feature_error(ruby) {
|
|
29
|
+
Ok(exception_class) => magnus::Error::new(exception_class, error),
|
|
30
|
+
Err(_) => magnus::Error::new(ruby.exception_runtime_error(), error),
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
magnus::Error::new(ruby.exception_runtime_error(), error)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
16
37
|
fn json_value_to_ruby(ruby: &Ruby, value: &serde_json::Value) -> Result<RbValue, magnus::Error> {
|
|
17
38
|
match value {
|
|
18
39
|
serde_json::Value::Null => Ok(ruby.qnil().as_value()),
|
|
@@ -117,7 +138,7 @@ impl WrappedOptionsProvider {
|
|
|
117
138
|
.get_all_options(&feature_names, None, Some(preferences))
|
|
118
139
|
{
|
|
119
140
|
Ok(options) => Ok(options.to_string()),
|
|
120
|
-
Err(e) => Err(
|
|
141
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
121
142
|
}
|
|
122
143
|
}
|
|
123
144
|
|
|
@@ -134,7 +155,7 @@ impl WrappedOptionsProvider {
|
|
|
134
155
|
.get_all_options(&feature_names, None, Some(preferences))
|
|
135
156
|
{
|
|
136
157
|
Ok(options) => json_value_to_ruby(ruby, &options),
|
|
137
|
-
Err(e) => Err(
|
|
158
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
138
159
|
}
|
|
139
160
|
}
|
|
140
161
|
|
|
@@ -147,7 +168,7 @@ impl WrappedOptionsProvider {
|
|
|
147
168
|
.0
|
|
148
169
|
.borrow()
|
|
149
170
|
.get_canonical_feature_name(&feature_name)
|
|
150
|
-
.map_err(|e|
|
|
171
|
+
.map_err(|e| map_feature_error(ruby, e))
|
|
151
172
|
}
|
|
152
173
|
|
|
153
174
|
fn get_canonical_feature_names(
|
|
@@ -159,7 +180,7 @@ impl WrappedOptionsProvider {
|
|
|
159
180
|
.0
|
|
160
181
|
.borrow()
|
|
161
182
|
.get_canonical_feature_names(&feature_names)
|
|
162
|
-
.map_err(|e|
|
|
183
|
+
.map_err(|e| map_feature_error(ruby, e))
|
|
163
184
|
}
|
|
164
185
|
|
|
165
186
|
fn get_feature_metadata_json(&self, canonical_feature_name: String) -> Option<String> {
|
|
@@ -191,7 +212,7 @@ impl WrappedOptionsProvider {
|
|
|
191
212
|
.get_filtered_feature_names(&feature_names, Some(preferences))
|
|
192
213
|
{
|
|
193
214
|
Ok(features) => Ok(features),
|
|
194
|
-
Err(e) => Err(
|
|
215
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
195
216
|
}
|
|
196
217
|
}
|
|
197
218
|
|
|
@@ -208,7 +229,7 @@ impl WrappedOptionsProvider {
|
|
|
208
229
|
.get_options_with_preferences(&key, &feature_names, None, None)
|
|
209
230
|
{
|
|
210
231
|
Ok(options) => Ok(options.to_string()),
|
|
211
|
-
Err(e) => Err(
|
|
232
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
212
233
|
}
|
|
213
234
|
}
|
|
214
235
|
|
|
@@ -227,7 +248,7 @@ impl WrappedOptionsProvider {
|
|
|
227
248
|
Some(preferences),
|
|
228
249
|
) {
|
|
229
250
|
Ok(options) => Ok(options.to_string()),
|
|
230
|
-
Err(e) => Err(
|
|
251
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
231
252
|
}
|
|
232
253
|
}
|
|
233
254
|
|
|
@@ -243,7 +264,7 @@ impl WrappedOptionsProvider {
|
|
|
243
264
|
.get_options_with_preferences(&key, &feature_names, None, None)
|
|
244
265
|
{
|
|
245
266
|
Ok(options) => json_value_to_ruby(ruby, &options),
|
|
246
|
-
Err(e) => Err(
|
|
267
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
247
268
|
}
|
|
248
269
|
}
|
|
249
270
|
|
|
@@ -262,7 +283,7 @@ impl WrappedOptionsProvider {
|
|
|
262
283
|
Some(preferences),
|
|
263
284
|
) {
|
|
264
285
|
Ok(options) => json_value_to_ruby(ruby, &options),
|
|
265
|
-
Err(e) => Err(
|
|
286
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
266
287
|
}
|
|
267
288
|
}
|
|
268
289
|
|
|
@@ -363,7 +384,7 @@ impl WrappedOptionsWatcher {
|
|
|
363
384
|
.get_all_options(&feature_names, None, Some(preferences))
|
|
364
385
|
{
|
|
365
386
|
Ok(options) => Ok(options.to_string()),
|
|
366
|
-
Err(e) => Err(
|
|
387
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
367
388
|
}
|
|
368
389
|
}
|
|
369
390
|
|
|
@@ -380,7 +401,7 @@ impl WrappedOptionsWatcher {
|
|
|
380
401
|
.get_all_options(&feature_names, None, Some(preferences))
|
|
381
402
|
{
|
|
382
403
|
Ok(options) => json_value_to_ruby(ruby, &options),
|
|
383
|
-
Err(e) => Err(
|
|
404
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
384
405
|
}
|
|
385
406
|
}
|
|
386
407
|
|
|
@@ -393,7 +414,7 @@ impl WrappedOptionsWatcher {
|
|
|
393
414
|
.0
|
|
394
415
|
.borrow()
|
|
395
416
|
.get_canonical_feature_name(&feature_name)
|
|
396
|
-
.map_err(|e|
|
|
417
|
+
.map_err(|e| map_feature_error(ruby, e))
|
|
397
418
|
}
|
|
398
419
|
|
|
399
420
|
fn get_canonical_feature_names(
|
|
@@ -405,7 +426,7 @@ impl WrappedOptionsWatcher {
|
|
|
405
426
|
.0
|
|
406
427
|
.borrow()
|
|
407
428
|
.get_canonical_feature_names(&feature_names)
|
|
408
|
-
.map_err(|e|
|
|
429
|
+
.map_err(|e| map_feature_error(ruby, e))
|
|
409
430
|
}
|
|
410
431
|
|
|
411
432
|
fn get_feature_metadata_json(&self, canonical_feature_name: String) -> Option<String> {
|
|
@@ -436,7 +457,7 @@ impl WrappedOptionsWatcher {
|
|
|
436
457
|
.get_filtered_feature_names(&feature_names, Some(preferences))
|
|
437
458
|
{
|
|
438
459
|
Ok(features) => Ok(features),
|
|
439
|
-
Err(e) => Err(
|
|
460
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
440
461
|
}
|
|
441
462
|
}
|
|
442
463
|
|
|
@@ -452,7 +473,7 @@ impl WrappedOptionsWatcher {
|
|
|
452
473
|
.get_options_with_preferences(&key, &feature_names, None, None)
|
|
453
474
|
{
|
|
454
475
|
Ok(options) => Ok(options.to_string()),
|
|
455
|
-
Err(e) => Err(
|
|
476
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
456
477
|
}
|
|
457
478
|
}
|
|
458
479
|
|
|
@@ -471,7 +492,7 @@ impl WrappedOptionsWatcher {
|
|
|
471
492
|
Some(preferences),
|
|
472
493
|
) {
|
|
473
494
|
Ok(options) => Ok(options.to_string()),
|
|
474
|
-
Err(e) => Err(
|
|
495
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
475
496
|
}
|
|
476
497
|
}
|
|
477
498
|
|
|
@@ -487,7 +508,7 @@ impl WrappedOptionsWatcher {
|
|
|
487
508
|
.get_options_with_preferences(&key, &feature_names, None, None)
|
|
488
509
|
{
|
|
489
510
|
Ok(options) => json_value_to_ruby(ruby, &options),
|
|
490
|
-
Err(e) => Err(
|
|
511
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
491
512
|
}
|
|
492
513
|
}
|
|
493
514
|
|
|
@@ -506,7 +527,7 @@ impl WrappedOptionsWatcher {
|
|
|
506
527
|
Some(preferences),
|
|
507
528
|
) {
|
|
508
529
|
Ok(options) => json_value_to_ruby(ruby, &options),
|
|
509
|
-
Err(e) => Err(
|
|
530
|
+
Err(e) => Err(map_feature_error(ruby, e)),
|
|
510
531
|
}
|
|
511
532
|
}
|
|
512
533
|
|
|
@@ -551,6 +572,8 @@ impl WrappedOptionsWatcherBuilder {
|
|
|
551
572
|
fn init(ruby: &Ruby) -> Result<(), magnus::Error> {
|
|
552
573
|
let module = ruby.define_module("Optify")?;
|
|
553
574
|
|
|
575
|
+
module.define_error("UnknownFeatureError", ruby.exception_standard_error())?;
|
|
576
|
+
|
|
554
577
|
let builder_class = module.define_class("OptionsProviderBuilder", ruby.class_object())?;
|
|
555
578
|
|
|
556
579
|
builder_class
|
|
@@ -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
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
# Tools for working with configurations declared in files.
|
|
5
5
|
module Optify
|
|
6
|
+
# Raised when a feature name is not found in the registry.
|
|
7
|
+
class UnknownFeatureError < StandardError
|
|
8
|
+
end
|
|
9
|
+
|
|
6
10
|
# DEPRECATED: Use `Optify::FromHashable` instead.
|
|
7
11
|
# A base class for classes from configuration files.
|
|
8
12
|
# Classes that derive from this can easily be used with `Optify::OptionsProvider.get_options`
|
|
@@ -19,6 +23,37 @@ module Optify
|
|
|
19
23
|
class CacheOptions < FromHashable
|
|
20
24
|
end
|
|
21
25
|
|
|
26
|
+
# The mode for the cache.
|
|
27
|
+
module CacheMode
|
|
28
|
+
# Non-thread-safe LRU cache.
|
|
29
|
+
# Should be faster than `THREAD_SAFE` for single-threaded applications.
|
|
30
|
+
NOT_THREAD_SAFE = T.let(:not_thread_safe, Symbol)
|
|
31
|
+
# Thread-safe LRU cache.
|
|
32
|
+
THREAD_SAFE = T.let(:thread_safe, Symbol)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Options for initializing the cache.
|
|
36
|
+
class CacheInitOptions
|
|
37
|
+
sig { returns(T.nilable(Integer)) }
|
|
38
|
+
attr_reader :max_size
|
|
39
|
+
|
|
40
|
+
# A value from `CacheMode`.
|
|
41
|
+
sig { returns(Symbol) }
|
|
42
|
+
attr_reader :mode
|
|
43
|
+
|
|
44
|
+
# Initializes the cache options.
|
|
45
|
+
# Defaults to a non-thread-safe unlimited size cache for backwards compatibility
|
|
46
|
+
# with how this library was originally configured with an unbounded hash as the case.
|
|
47
|
+
# @param mode A value from `CacheMode`.
|
|
48
|
+
sig do
|
|
49
|
+
params(
|
|
50
|
+
max_size: T.nilable(Integer),
|
|
51
|
+
mode: Symbol,
|
|
52
|
+
).void
|
|
53
|
+
end
|
|
54
|
+
def initialize(max_size: nil, mode: CacheMode::NOT_THREAD_SAFE); end
|
|
55
|
+
end
|
|
56
|
+
|
|
22
57
|
# Information about a feature.
|
|
23
58
|
class OptionsMetadata < FromHashable
|
|
24
59
|
sig { returns(T.nilable(T::Array[String])) }
|
|
@@ -188,7 +223,7 @@ module Optify
|
|
|
188
223
|
sig do
|
|
189
224
|
params(
|
|
190
225
|
feature_names: T::Array[String],
|
|
191
|
-
preferences: GetOptionsPreferences
|
|
226
|
+
preferences: GetOptionsPreferences,
|
|
192
227
|
)
|
|
193
228
|
.returns(T::Array[String])
|
|
194
229
|
end
|
|
@@ -211,7 +246,7 @@ module Optify
|
|
|
211
246
|
feature_names: T::Array[String],
|
|
212
247
|
config_class: T::Class[T.type_parameter(:Config)],
|
|
213
248
|
cache_options: T.nilable(CacheOptions),
|
|
214
|
-
preferences: T.nilable(Optify::GetOptionsPreferences)
|
|
249
|
+
preferences: T.nilable(Optify::GetOptionsPreferences),
|
|
215
250
|
)
|
|
216
251
|
.returns(T.type_parameter(:Config))
|
|
217
252
|
end
|
|
@@ -264,8 +299,11 @@ module Optify
|
|
|
264
299
|
|
|
265
300
|
# (Optional) Eagerly initializes the cache.
|
|
266
301
|
# @return `self`.
|
|
267
|
-
sig
|
|
268
|
-
|
|
302
|
+
sig do
|
|
303
|
+
params(cache_init_options: T.nilable(CacheInitOptions))
|
|
304
|
+
.returns(T.self_type)
|
|
305
|
+
end
|
|
306
|
+
def init(cache_init_options = nil); end
|
|
269
307
|
|
|
270
308
|
private
|
|
271
309
|
|
data/sig/optify.rbs
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
module Optify
|
|
3
3
|
end
|
|
4
4
|
|
|
5
|
+
# Raised when a feature name is not found in the registry.
|
|
6
|
+
class Optify::UnknownFeatureError < StandardError
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
# DEPRECATED: Use `Optify::FromHashable` instead.
|
|
6
10
|
# A base class for classes from configuration files.
|
|
7
11
|
# Classes that derive from this can easily be used with `Optify::OptionsProvider.get_options`
|
|
@@ -17,6 +21,22 @@ end
|
|
|
17
21
|
class Optify::CacheOptions < FromHashable
|
|
18
22
|
end
|
|
19
23
|
|
|
24
|
+
# The mode for the cache.
|
|
25
|
+
module Optify::CacheMode
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Optify::Optify::CacheMode::NOT_THREAD_SAFE: Symbol
|
|
29
|
+
|
|
30
|
+
Optify::Optify::CacheMode::THREAD_SAFE: Symbol
|
|
31
|
+
|
|
32
|
+
# Options for initializing the cache.
|
|
33
|
+
class Optify::CacheInitOptions
|
|
34
|
+
# A value from `CacheMode`.
|
|
35
|
+
def initialize: () -> Integer?
|
|
36
|
+
| () -> Symbol
|
|
37
|
+
| (?max_size: Integer? max_size, ?mode: Symbol mode) -> void
|
|
38
|
+
end
|
|
39
|
+
|
|
20
40
|
# Information about a feature.
|
|
21
41
|
class Optify::OptionsMetadata < FromHashable
|
|
22
42
|
def aliases: () -> ::Array[String]?
|
|
@@ -163,9 +183,7 @@ module Optify::ProviderModule
|
|
|
163
183
|
# @return Whether the feature has conditions.
|
|
164
184
|
def conditions?: (String canonical_feature_name) -> bool
|
|
165
185
|
|
|
166
|
-
|
|
167
|
-
# @return `self`.
|
|
168
|
-
def init: () -> self
|
|
186
|
+
def init: (?CacheInitOptions? cache_init_options) -> self
|
|
169
187
|
|
|
170
188
|
# Map aliases or canonical feature names (perhaps derived from a file names) to the canonical feature names.
|
|
171
189
|
# Canonical feature names map to themselves.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: optify-config
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.20.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin D. Harris
|
|
@@ -37,6 +37,20 @@ dependencies:
|
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
39
|
version: 0.2.1
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: sin_lru_redux
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 2.5.2
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 2.5.2
|
|
40
54
|
- !ruby/object:Gem::Dependency
|
|
41
55
|
name: sorbet-runtime
|
|
42
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -91,14 +105,14 @@ dependencies:
|
|
|
91
105
|
requirements:
|
|
92
106
|
- - "~>"
|
|
93
107
|
- !ruby/object:Gem::Version
|
|
94
|
-
version: 1.
|
|
108
|
+
version: 1.82.1
|
|
95
109
|
type: :development
|
|
96
110
|
prerelease: false
|
|
97
111
|
version_requirements: !ruby/object:Gem::Requirement
|
|
98
112
|
requirements:
|
|
99
113
|
- - "~>"
|
|
100
114
|
- !ruby/object:Gem::Version
|
|
101
|
-
version: 1.
|
|
115
|
+
version: 1.82.1
|
|
102
116
|
- !ruby/object:Gem::Dependency
|
|
103
117
|
name: rubocop-sorbet
|
|
104
118
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -175,6 +189,7 @@ files:
|
|
|
175
189
|
- ext/optify_ruby/src/preferences.rs
|
|
176
190
|
- lib/optify.rb
|
|
177
191
|
- lib/optify_ruby/base_config.rb
|
|
192
|
+
- lib/optify_ruby/cache_init_options.rb
|
|
178
193
|
- lib/optify_ruby/get_options_preferences.rb
|
|
179
194
|
- lib/optify_ruby/implementation.rb
|
|
180
195
|
- lib/optify_ruby/options_metadata.rb
|