optify-config 1.19.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/rbi/optify.rbi +4 -0
- data/sig/optify.rbs +4 -0
- 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: 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
|
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`
|
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`
|