optify-config 1.6.0 → 1.7.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/src/lib.rs +8 -17
- data/lib/optify_ruby/base_config.rb +46 -5
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c39f6b23931576d844b9c6c4991a373f96198f009e4f4a78227adcb373162f2c
|
4
|
+
data.tar.gz: 98cd040744bdfeab713795c276b58b472b5e9fff7d4c7bf164f5196aab94e812
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3c2ae32795dbca9e1a9a48eebbec2b6a854e44071554693dbad9c226ec94624cab294b6ed8fa790a0bbd7bbfec5a59bc42cb4d61d475299fde1c41ff0476738
|
7
|
+
data.tar.gz: 50bcc0e02ced878b270fd3d98a4f7ba46c66eb67f0b1913429e78ef4362dc30ec9045dc22c00c006424849cfe590b77c8219bac5dd8a6e7a05402f26a966b1c1
|
data/ext/optify_ruby/src/lib.rs
CHANGED
@@ -2,7 +2,6 @@ use magnus::{function, method, prelude::*, wrap, Object, Ruby};
|
|
2
2
|
use optify::builder::OptionsProviderBuilder;
|
3
3
|
use optify::builder::OptionsRegistryBuilder;
|
4
4
|
use optify::builder::OptionsWatcherBuilder;
|
5
|
-
use optify::convert_to_str_slice;
|
6
5
|
use optify::provider::GetOptionsPreferences;
|
7
6
|
use optify::provider::OptionsProvider;
|
8
7
|
use optify::provider::OptionsRegistry;
|
@@ -70,11 +69,10 @@ impl WrappedOptionsProvider {
|
|
70
69
|
preferences: &MutGetOptionsPreferences,
|
71
70
|
) -> Result<String, magnus::Error> {
|
72
71
|
let preferences = convert_preferences(preferences);
|
73
|
-
let features = convert_to_str_slice!(feature_names);
|
74
72
|
match rb_self
|
75
73
|
.0
|
76
74
|
.borrow()
|
77
|
-
.get_all_options(&
|
75
|
+
.get_all_options(&feature_names, None, Some(&preferences))
|
78
76
|
{
|
79
77
|
Ok(options) => Ok(options.to_string()),
|
80
78
|
Err(e) => Err(magnus::Error::new(ruby.exception_runtime_error(), e)),
|
@@ -98,11 +96,10 @@ impl WrappedOptionsProvider {
|
|
98
96
|
rb_self: &Self,
|
99
97
|
feature_names: Vec<String>,
|
100
98
|
) -> Result<Vec<String>, magnus::Error> {
|
101
|
-
let features = convert_to_str_slice!(feature_names);
|
102
99
|
rb_self
|
103
100
|
.0
|
104
101
|
.borrow()
|
105
|
-
.get_canonical_feature_names(&
|
102
|
+
.get_canonical_feature_names(&feature_names)
|
106
103
|
.map_err(|e| magnus::Error::new(ruby.exception_arg_error(), e))
|
107
104
|
}
|
108
105
|
|
@@ -129,11 +126,10 @@ impl WrappedOptionsProvider {
|
|
129
126
|
key: String,
|
130
127
|
feature_names: Vec<String>,
|
131
128
|
) -> Result<String, magnus::Error> {
|
132
|
-
let features = convert_to_str_slice!(feature_names);
|
133
129
|
match rb_self
|
134
130
|
.0
|
135
131
|
.borrow()
|
136
|
-
.get_options_with_preferences(&key, &
|
132
|
+
.get_options_with_preferences(&key, &feature_names, None, None)
|
137
133
|
{
|
138
134
|
Ok(options) => Ok(options.to_string()),
|
139
135
|
Err(e) => Err(magnus::Error::new(ruby.exception_runtime_error(), e)),
|
@@ -148,10 +144,9 @@ impl WrappedOptionsProvider {
|
|
148
144
|
preferences: &MutGetOptionsPreferences,
|
149
145
|
) -> Result<String, magnus::Error> {
|
150
146
|
let preferences = convert_preferences(preferences);
|
151
|
-
let features = convert_to_str_slice!(feature_names);
|
152
147
|
match rb_self.0.borrow().get_options_with_preferences(
|
153
148
|
&key,
|
154
|
-
&
|
149
|
+
&feature_names,
|
155
150
|
None,
|
156
151
|
Some(&preferences),
|
157
152
|
) {
|
@@ -216,11 +211,10 @@ impl WrappedOptionsWatcher {
|
|
216
211
|
preferences: &MutGetOptionsPreferences,
|
217
212
|
) -> Result<String, magnus::Error> {
|
218
213
|
let preferences = convert_preferences(preferences);
|
219
|
-
let features = convert_to_str_slice!(feature_names);
|
220
214
|
match rb_self
|
221
215
|
.0
|
222
216
|
.borrow()
|
223
|
-
.get_all_options(&
|
217
|
+
.get_all_options(&feature_names, None, Some(&preferences))
|
224
218
|
{
|
225
219
|
Ok(options) => Ok(options.to_string()),
|
226
220
|
Err(e) => Err(magnus::Error::new(ruby.exception_runtime_error(), e)),
|
@@ -244,11 +238,10 @@ impl WrappedOptionsWatcher {
|
|
244
238
|
rb_self: &Self,
|
245
239
|
feature_names: Vec<String>,
|
246
240
|
) -> Result<Vec<String>, magnus::Error> {
|
247
|
-
let features = convert_to_str_slice!(feature_names);
|
248
241
|
rb_self
|
249
242
|
.0
|
250
243
|
.borrow()
|
251
|
-
.get_canonical_feature_names(&
|
244
|
+
.get_canonical_feature_names(&feature_names)
|
252
245
|
.map_err(|e| magnus::Error::new(ruby.exception_arg_error(), e))
|
253
246
|
}
|
254
247
|
|
@@ -273,11 +266,10 @@ impl WrappedOptionsWatcher {
|
|
273
266
|
key: String,
|
274
267
|
feature_names: Vec<String>,
|
275
268
|
) -> Result<String, magnus::Error> {
|
276
|
-
let features = convert_to_str_slice!(feature_names);
|
277
269
|
match rb_self
|
278
270
|
.0
|
279
271
|
.borrow()
|
280
|
-
.get_options_with_preferences(&key, &
|
272
|
+
.get_options_with_preferences(&key, &feature_names, None, None)
|
281
273
|
{
|
282
274
|
Ok(options) => Ok(options.to_string()),
|
283
275
|
Err(e) => Err(magnus::Error::new(ruby.exception_runtime_error(), e)),
|
@@ -292,10 +284,9 @@ impl WrappedOptionsWatcher {
|
|
292
284
|
preferences: &MutGetOptionsPreferences,
|
293
285
|
) -> Result<String, magnus::Error> {
|
294
286
|
let preferences = convert_preferences(preferences);
|
295
|
-
let features = convert_to_str_slice!(feature_names);
|
296
287
|
match rb_self.0.borrow().get_options_with_preferences(
|
297
288
|
&key,
|
298
|
-
&
|
289
|
+
&feature_names,
|
299
290
|
None,
|
300
291
|
Some(&preferences),
|
301
292
|
) {
|
@@ -8,8 +8,7 @@ module Optify
|
|
8
8
|
# A base class for classes from configuration files.
|
9
9
|
# Classes that derive from this can easily be used with `Optify::OptionsProvider.get_options`
|
10
10
|
# because they will have an implementation of `from_hash` that works recursively.
|
11
|
-
# This class is a work in progress with minimal error handling
|
12
|
-
# and doesn't handle certain cases such as nilable types yet.
|
11
|
+
# This class is a work in progress with minimal error handling.
|
13
12
|
# It may be moved to another gem in the future.
|
14
13
|
class BaseConfig
|
15
14
|
extend T::Sig
|
@@ -26,7 +25,10 @@ module Optify
|
|
26
25
|
instance = new
|
27
26
|
|
28
27
|
hash.each do |key, value|
|
29
|
-
|
28
|
+
sig = T::Utils.signature_for_method(instance_method(key))
|
29
|
+
raise "A Sorbet signature is required for `#{name}.#{key}`." if sig.nil?
|
30
|
+
|
31
|
+
sig_return_type = sig.return_type
|
30
32
|
value = _convert_value(value, sig_return_type)
|
31
33
|
instance.instance_variable_set("@#{key}", value)
|
32
34
|
end
|
@@ -104,8 +106,47 @@ module Optify
|
|
104
106
|
return true if other.equal?(self)
|
105
107
|
return false unless other.is_a?(self.class)
|
106
108
|
|
107
|
-
instance_variables.all? do |
|
108
|
-
instance_variable_get(
|
109
|
+
instance_variables.all? do |name|
|
110
|
+
instance_variable_get(name) == other.instance_variable_get(name)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Convert this object to a Hash recursively.
|
115
|
+
# This is mostly the reverse operation of `from_hash`,
|
116
|
+
# as keys will be symbols
|
117
|
+
# and `from_hash` will convert strings to symbols if that's how the attribute is declared.
|
118
|
+
# @return [Hash] The hash representation of this object.
|
119
|
+
#: () -> Hash[Symbol, untyped]
|
120
|
+
def to_h
|
121
|
+
result = Hash.new(instance_variables.size)
|
122
|
+
|
123
|
+
instance_variables.each do |var_name|
|
124
|
+
# Remove the @ prefix to get the method name
|
125
|
+
method_name = var_name.to_s[1..] #: as !nil
|
126
|
+
value = instance_variable_get(var_name)
|
127
|
+
result[method_name.to_sym] = _convert_value_to_hash(value)
|
128
|
+
end
|
129
|
+
|
130
|
+
result
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
#: (untyped value) -> untyped
|
136
|
+
def _convert_value_to_hash(value)
|
137
|
+
case value
|
138
|
+
when Array
|
139
|
+
value.map { |v| _convert_value_to_hash(v) }
|
140
|
+
when Hash
|
141
|
+
value.transform_values { |v| _convert_value_to_hash(v) }
|
142
|
+
when nil
|
143
|
+
nil
|
144
|
+
else
|
145
|
+
if value.respond_to?(:to_h)
|
146
|
+
value.to_h
|
147
|
+
else
|
148
|
+
value
|
149
|
+
end
|
109
150
|
end
|
110
151
|
end
|
111
152
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optify-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin D. Harris
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-06-
|
10
|
+
date: 2025-06-23 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rb_sys
|
@@ -29,14 +29,14 @@ dependencies:
|
|
29
29
|
requirements:
|
30
30
|
- - "~>"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.5.
|
32
|
+
version: 0.5.12167
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.5.
|
39
|
+
version: 0.5.12167
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rake-compiler
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
@@ -57,42 +57,42 @@ dependencies:
|
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: 4.0.0.dev.4
|
61
61
|
type: :development
|
62
62
|
prerelease: false
|
63
63
|
version_requirements: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
67
|
+
version: 4.0.0.dev.4
|
68
68
|
- !ruby/object:Gem::Dependency
|
69
69
|
name: sorbet
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.5.
|
74
|
+
version: 0.5.12167
|
75
75
|
type: :development
|
76
76
|
prerelease: false
|
77
77
|
version_requirements: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 0.5.
|
81
|
+
version: 0.5.12167
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: tapioca
|
84
84
|
requirement: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 0.
|
88
|
+
version: 0.17.2
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
91
|
version_requirements: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: 0.
|
95
|
+
version: 0.17.2
|
96
96
|
- !ruby/object:Gem::Dependency
|
97
97
|
name: test-unit
|
98
98
|
requirement: !ruby/object:Gem::Requirement
|