optify-config 0.4.0-aarch64-linux → 0.4.2-aarch64-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.1/optify_ruby.so +0 -0
- data/lib/optify_ruby/3.2/optify_ruby.so +0 -0
- data/lib/optify_ruby/base_config.rb +57 -14
- data/lib/optify_ruby/implementation.rb +7 -5
- data/rbi/optify.rbi +6 -4
- metadata +6 -4
- /data/lib/optify_ruby/{optify_ruby.so → 3.4/optify_ruby.so} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 108d884c56a8953b283d19cc6c467bfba15bd9c4bc3536735d81e7e72e091b2f
|
4
|
+
data.tar.gz: 57a735915f6d0355c2cbf853c41abad01739c4e4f7fb252326dda14a196d14a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4816ac528e2ff724634f81f7b779e7cf1ebff93deff61189711ac2f337c22010848aac8b554b60bf56f5884f8153360f1009a1d8af9bd8aa0e45ff2c8cb7e05c
|
7
|
+
data.tar.gz: fa0b263fa394d6ac2c9d3e542f7b98c11a619529f562f79674b510b64ec99e2aaf65afbc28fdc2cef4cd0e8ce1f263f02dec47b964da0846726ca8081312ddd2
|
Binary file
|
Binary file
|
@@ -18,6 +18,7 @@ module Optify
|
|
18
18
|
|
19
19
|
# Create a new instance of the class from a hash.
|
20
20
|
#
|
21
|
+
# This is a class method that so that it can set members with private setters.
|
21
22
|
# @param hash [Hash] The hash to create the instance from.
|
22
23
|
# @return The new instance.
|
23
24
|
sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.attached_class) }
|
@@ -25,24 +26,66 @@ module Optify
|
|
25
26
|
result = new
|
26
27
|
|
27
28
|
hash.each do |key, value|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
29
|
+
sig_return_type = T::Utils.signature_for_method(instance_method(key)).return_type
|
30
|
+
value = _convert_value(value, sig_return_type)
|
31
|
+
result.instance_variable_set("@#{key}", value)
|
32
|
+
end
|
33
|
+
result
|
34
|
+
end
|
35
|
+
|
36
|
+
sig { params(value: T.untyped, type: T.untyped).returns(T.untyped) }
|
37
|
+
def self._convert_value(value, type)
|
38
|
+
case value
|
39
|
+
when Array
|
40
|
+
type = if type.type.respond_to?(:unwrap_nilable)
|
41
|
+
# Handle nilable array.
|
42
|
+
type.type.unwrap_nilable
|
43
|
+
else
|
44
|
+
# Handle array of 1 type.
|
45
|
+
type.type
|
46
|
+
end
|
47
|
+
return value.map { |v| _convert_value(v, type) }
|
48
|
+
when Hash
|
49
|
+
# Handle nilable hash.
|
50
|
+
type = type.unwrap_nilable if type.respond_to?(:unwrap_nilable)
|
51
|
+
return _convert_hash(value, type)
|
52
|
+
end
|
53
|
+
|
54
|
+
value
|
55
|
+
end
|
56
|
+
|
57
|
+
sig do
|
58
|
+
params(
|
59
|
+
hash: T::Hash[T.untyped, T.untyped],
|
60
|
+
type: T.untyped
|
61
|
+
).returns(T.untyped)
|
62
|
+
end
|
63
|
+
def self._convert_hash(hash, type) # rubocop:disable Metrics/PerceivedComplexity
|
64
|
+
if type.respond_to?(:raw_type)
|
65
|
+
# There is an object for the hash.
|
66
|
+
type_for_hash = type.raw_type
|
67
|
+
return type_for_hash.from_hash(hash) if type_for_hash.respond_to?(:from_hash)
|
68
|
+
elsif type.instance_of?(T::Types::TypedHash)
|
69
|
+
# The hash should be a hash, but the values might be objects to convert.
|
70
|
+
type_for_values = type.values
|
71
|
+
|
72
|
+
if type_for_values.respond_to?(:raw_type)
|
73
|
+
raw_type_for_values = type_for_values.raw_type
|
74
|
+
if raw_type_for_values.respond_to?(:from_hash)
|
75
|
+
# Use proper types.
|
76
|
+
return hash.transform_values { |v| raw_type_for_values.from_hash(v) }
|
40
77
|
end
|
41
78
|
end
|
42
79
|
|
43
|
-
|
80
|
+
# The values are not recognized objects.
|
81
|
+
return hash.transform_values { |v| _convert_value(v, type_for_values) }
|
44
82
|
end
|
45
|
-
|
83
|
+
|
84
|
+
# Fallback to doing nothing.
|
85
|
+
# This can happen if there are is no type information for a key in the hash.
|
86
|
+
hash
|
46
87
|
end
|
88
|
+
|
89
|
+
private_class_method :_convert_hash, :_convert_value
|
47
90
|
end
|
48
91
|
end
|
@@ -50,15 +50,16 @@ module Optify
|
|
50
50
|
def get_options(key, feature_names, config_class, cache_options = nil)
|
51
51
|
return get_options_with_cache(key, feature_names, config_class, cache_options) if cache_options
|
52
52
|
|
53
|
-
options_json = get_options_json(key, feature_names)
|
54
|
-
h = JSON.parse(options_json, object_class: Hash)
|
55
53
|
unless config_class.respond_to?(:from_hash)
|
56
54
|
raise NotImplementedError,
|
57
55
|
"The provided config class must implement `from_hash` as a class method
|
58
|
-
|
56
|
+
in order to be converted.
|
57
|
+
Recommended: extend `Optify::BaseConfig`."
|
59
58
|
end
|
60
59
|
|
61
|
-
|
60
|
+
options_json = get_options_json(key, feature_names)
|
61
|
+
hash = JSON.parse(options_json)
|
62
|
+
T.unsafe(config_class).from_hash(hash)
|
62
63
|
end
|
63
64
|
|
64
65
|
private
|
@@ -79,7 +80,7 @@ module Optify
|
|
79
80
|
# Cache directly in Ruby instead of Rust because:
|
80
81
|
# * Avoid any possible conversion overhead.
|
81
82
|
# * Memory management: probably better to do it in Ruby for a Ruby app and avoid memory in Rust.
|
82
|
-
# TODO:
|
83
|
+
# TODO: Consider aliases when caching. Right now, they are only visible in Rust
|
83
84
|
# and we don't want the cache in Rust because we won't to avoid any conversion overhead.
|
84
85
|
@cache ||= T.let({}, T.nilable(T::Hash[T.untyped, T.untyped]))
|
85
86
|
cache_key = [key, feature_names, config_class]
|
@@ -87,6 +88,7 @@ module Optify
|
|
87
88
|
return result unless result.equal?(NOT_FOUND_IN_CACHE_SENTINEL)
|
88
89
|
|
89
90
|
result = get_options(key, feature_names, config_class)
|
91
|
+
T.unsafe(result).freeze if T.unsafe(result).respond_to?(:freeze)
|
90
92
|
|
91
93
|
@cache[cache_key] = result
|
92
94
|
end
|
data/rbi/optify.rbi
CHANGED
@@ -14,6 +14,7 @@ module Optify
|
|
14
14
|
|
15
15
|
# Create a new instance of the class from a hash.
|
16
16
|
#
|
17
|
+
# This is a class method that so that it can set members with private setters.
|
17
18
|
# @param hash [Hash] The hash to create the instance from.
|
18
19
|
# @return The new instance.
|
19
20
|
sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.attached_class) }
|
@@ -33,6 +34,7 @@ module Optify
|
|
33
34
|
# @param feature_names [Array<String>] The enabled feature names to use to build the options.
|
34
35
|
# @param config_class [ConfigType] The class of the configuration to return.
|
35
36
|
# It is recommended to use a class that extends `Optify::BaseConfig` because it implements `from_hash`.
|
37
|
+
# @param cache_options Set this if caching is desired. Only very simple caching is supported for now.
|
36
38
|
# @return [ConfigType] The options.
|
37
39
|
sig do
|
38
40
|
type_parameters(:Config)
|
@@ -41,10 +43,10 @@ module Optify
|
|
41
43
|
feature_names: T::Array[String],
|
42
44
|
config_class: T::Class[T.type_parameter(:Config)],
|
43
45
|
cache_options: T.nilable(CacheOptions)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
)
|
47
|
+
.returns(T.type_parameter(:Config))
|
48
|
+
end
|
49
|
+
def get_options(key, feature_names, config_class, cache_options = nil); end
|
48
50
|
|
49
51
|
# Fetches options in JSON format based on the provided key and feature names.
|
50
52
|
#
|
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: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: aarch64-linux
|
6
6
|
authors:
|
7
7
|
- Justin D. Harris
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sorbet-runtime
|
@@ -89,9 +89,11 @@ extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
91
|
- lib/optify.rb
|
92
|
+
- lib/optify_ruby/3.1/optify_ruby.so
|
93
|
+
- lib/optify_ruby/3.2/optify_ruby.so
|
94
|
+
- lib/optify_ruby/3.4/optify_ruby.so
|
92
95
|
- lib/optify_ruby/base_config.rb
|
93
96
|
- lib/optify_ruby/implementation.rb
|
94
|
-
- lib/optify_ruby/optify_ruby.so
|
95
97
|
- rbi/optify.rbi
|
96
98
|
homepage: https://github.com/juharris/optify
|
97
99
|
licenses:
|
@@ -107,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
109
|
requirements:
|
108
110
|
- - ">="
|
109
111
|
- !ruby/object:Gem::Version
|
110
|
-
version: '3.
|
112
|
+
version: '3.1'
|
111
113
|
- - "<"
|
112
114
|
- !ruby/object:Gem::Version
|
113
115
|
version: 3.5.dev
|
File without changes
|