optify-config 0.4.5-x86_64-linux → 0.5.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.1/optify_ruby.so +0 -0
- data/lib/optify_ruby/3.2/optify_ruby.so +0 -0
- data/lib/optify_ruby/3.4/optify_ruby.so +0 -0
- data/lib/optify_ruby/base_config.rb +5 -4
- data/lib/optify_ruby/implementation.rb +32 -14
- data/rbi/optify.rbi +38 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6d592561af2272187516372a4c4c8dcf3b2ff66c3eaf0d4188f94a97561c6b7
|
4
|
+
data.tar.gz: 485852f9405f080f684400e552b42de1abf43e075f4a3fd13097223edf279425
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d79d2bfbd4cdf84c6c7126c390dd4fadde5857232e8ea26a6b5687a3a9c344f2cb17887905235ec37d0b2e35e0bd167837178a3e48ae4018d384f86e9a8de696
|
7
|
+
data.tar.gz: b91df6d5c3bb954781cb5e9be9d4f425df17c829ecf0fe4afc132510298988a5e0fb51ffd6f159cc5a70ed0e18d1d583ecdad8746a05403a6db16e3b1828a03a
|
Binary file
|
Binary file
|
Binary file
|
@@ -16,7 +16,7 @@ module Optify
|
|
16
16
|
extend T::Helpers
|
17
17
|
abstract!
|
18
18
|
|
19
|
-
# Create a new instance of the class from a hash.
|
19
|
+
# Create a new immutable instance of the class from a hash.
|
20
20
|
#
|
21
21
|
# This is a class method that so that it can set members with private setters.
|
22
22
|
# @param hash [Hash] The hash to create the instance from.
|
@@ -30,7 +30,8 @@ module Optify
|
|
30
30
|
value = _convert_value(value, sig_return_type)
|
31
31
|
result.instance_variable_set("@#{key}", value)
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
|
+
T.unsafe(result).freeze if T.unsafe(result).respond_to?(:freeze)
|
34
35
|
end
|
35
36
|
|
36
37
|
sig { params(value: T.untyped, type: T.untyped).returns(T.untyped) }
|
@@ -44,11 +45,11 @@ module Optify
|
|
44
45
|
# Handle array of 1 type.
|
45
46
|
type.type
|
46
47
|
end
|
47
|
-
return value.map { |v| _convert_value(v, type) }
|
48
|
+
return value.map { |v| _convert_value(v, type) }.freeze
|
48
49
|
when Hash
|
49
50
|
# Handle nilable hash.
|
50
51
|
type = type.unwrap_nilable if type.respond_to?(:unwrap_nilable)
|
51
|
-
return _convert_hash(value, type)
|
52
|
+
return _convert_hash(value, type).freeze
|
52
53
|
end
|
53
54
|
|
54
55
|
value
|
@@ -24,7 +24,8 @@ module Optify
|
|
24
24
|
# @param feature_names [Array<String>] The enabled feature names to use to build the options.
|
25
25
|
# @param config_class [ConfigType] The class of the configuration to return.
|
26
26
|
# It is recommended to use a class that extends `Optify::BaseConfig` because it implements `from_hash`.
|
27
|
-
# @param cache_options Set this if caching is desired. Only very simple caching is supported for now.
|
27
|
+
# @param cache_options [CacheOptions] Set this if caching is desired. Only very simple caching is supported for now.
|
28
|
+
# @param preferences [GetOptionsPreferences] The preferences to use when getting options.
|
28
29
|
# @return [ConfigType] The options.
|
29
30
|
sig do
|
30
31
|
type_parameters(:Config)
|
@@ -32,12 +33,13 @@ module Optify
|
|
32
33
|
key: String,
|
33
34
|
feature_names: T::Array[String],
|
34
35
|
config_class: T::Class[T.type_parameter(:Config)],
|
35
|
-
cache_options: T.nilable(CacheOptions)
|
36
|
+
cache_options: T.nilable(CacheOptions),
|
37
|
+
preferences: T.nilable(Optify::GetOptionsPreferences)
|
36
38
|
)
|
37
39
|
.returns(T.type_parameter(:Config))
|
38
40
|
end
|
39
|
-
def get_options(key, feature_names, config_class, cache_options = nil)
|
40
|
-
return get_options_with_cache(key, feature_names, config_class, cache_options) if cache_options
|
41
|
+
def get_options(key, feature_names, config_class, cache_options = nil, preferences = nil)
|
42
|
+
return get_options_with_cache(key, feature_names, config_class, cache_options, preferences) if cache_options
|
41
43
|
|
42
44
|
unless config_class.respond_to?(:from_hash)
|
43
45
|
raise NotImplementedError,
|
@@ -46,11 +48,23 @@ module Optify
|
|
46
48
|
Recommended: extend `Optify::BaseConfig`."
|
47
49
|
end
|
48
50
|
|
49
|
-
options_json =
|
51
|
+
options_json = if preferences
|
52
|
+
get_options_json_with_preferences(key, feature_names, preferences)
|
53
|
+
else
|
54
|
+
get_options_json(key, feature_names)
|
55
|
+
end
|
50
56
|
hash = JSON.parse(options_json)
|
51
57
|
T.unsafe(config_class).from_hash(hash)
|
52
58
|
end
|
53
59
|
|
60
|
+
# (Optional) Eagerly initializes the cache.
|
61
|
+
# @return [OptionsProvider] `self`.
|
62
|
+
sig { returns(OptionsProvider) }
|
63
|
+
def init
|
64
|
+
@cache = T.let({}, T.nilable(T::Hash[T.untyped, T.untyped]))
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
54
68
|
private
|
55
69
|
|
56
70
|
NOT_FOUND_IN_CACHE_SENTINEL = Object.new
|
@@ -61,25 +75,29 @@ module Optify
|
|
61
75
|
key: String,
|
62
76
|
feature_names: T::Array[String],
|
63
77
|
config_class: T::Class[T.type_parameter(:Config)],
|
64
|
-
_cache_options: CacheOptions
|
78
|
+
_cache_options: CacheOptions,
|
79
|
+
preferences: T.nilable(Optify::GetOptionsPreferences)
|
65
80
|
)
|
66
81
|
.returns(T.type_parameter(:Config))
|
67
82
|
end
|
68
|
-
def get_options_with_cache(key, feature_names, config_class, _cache_options)
|
83
|
+
def get_options_with_cache(key, feature_names, config_class, _cache_options, preferences = nil)
|
69
84
|
# Cache directly in Ruby instead of Rust because:
|
70
85
|
# * Avoid any possible conversion overhead.
|
71
86
|
# * Memory management: probably better to do it in Ruby for a Ruby app and avoid memory in Rust.
|
72
|
-
|
73
|
-
|
74
|
-
|
87
|
+
init unless @cache
|
88
|
+
feature_names = feature_names.map do |feature_name|
|
89
|
+
get_canonical_feature_name(feature_name)
|
90
|
+
end
|
91
|
+
|
75
92
|
cache_key = [key, feature_names, config_class]
|
76
|
-
result = @cache
|
93
|
+
result = @cache&.fetch(cache_key, NOT_FOUND_IN_CACHE_SENTINEL)
|
77
94
|
return result unless result.equal?(NOT_FOUND_IN_CACHE_SENTINEL)
|
78
95
|
|
79
|
-
|
80
|
-
|
96
|
+
preferences ||= GetOptionsPreferences.new
|
97
|
+
preferences.skip_feature_name_conversion = true
|
98
|
+
result = get_options(key, feature_names, config_class, nil, preferences)
|
81
99
|
|
82
|
-
@cache[cache_key] = result
|
100
|
+
T.must(@cache)[cache_key] = result
|
83
101
|
end
|
84
102
|
end
|
85
103
|
end
|
data/rbi/optify.rbi
CHANGED
@@ -26,15 +26,32 @@ module Optify
|
|
26
26
|
class CacheOptions < BaseConfig
|
27
27
|
end
|
28
28
|
|
29
|
+
# Preferences when getting options.
|
30
|
+
class GetOptionsPreferences
|
31
|
+
sig { params(value: T::Boolean).returns(GetOptionsPreferences) }
|
32
|
+
def skip_feature_name_conversion=(value); end
|
33
|
+
sig { returns(T::Boolean) }
|
34
|
+
def skip_feature_name_conversion; end
|
35
|
+
end
|
36
|
+
|
29
37
|
# Provides configurations based on keys and enabled feature names.
|
30
38
|
class OptionsProvider
|
39
|
+
# Map an alias or canonical feature name (perhaps derived from a file name) to a canonical feature name.
|
40
|
+
# Canonical feature names map to themselves.
|
41
|
+
#
|
42
|
+
# @param feature_name The name of an alias or a feature.
|
43
|
+
# @return The canonical feature name.
|
44
|
+
sig { params(feature_name: String).returns(String) }
|
45
|
+
def get_canonical_feature_name(feature_name); end
|
46
|
+
|
31
47
|
# Fetches options based on the provided key and feature names.
|
32
48
|
#
|
33
49
|
# @param key [String] the key to fetch options for.
|
34
50
|
# @param feature_names [Array<String>] The enabled feature names to use to build the options.
|
35
51
|
# @param config_class [ConfigType] The class of the configuration to return.
|
36
52
|
# 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.
|
53
|
+
# @param cache_options [CacheOptions] Set this if caching is desired. Only very simple caching is supported for now.
|
54
|
+
# @param preferences [GetOptionsPreferences] The preferences to use when getting options.
|
38
55
|
# @return [ConfigType] The options.
|
39
56
|
sig do
|
40
57
|
type_parameters(:Config)
|
@@ -42,11 +59,12 @@ module Optify
|
|
42
59
|
key: String,
|
43
60
|
feature_names: T::Array[String],
|
44
61
|
config_class: T::Class[T.type_parameter(:Config)],
|
45
|
-
cache_options: T.nilable(CacheOptions)
|
62
|
+
cache_options: T.nilable(CacheOptions),
|
63
|
+
preferences: T.nilable(Optify::GetOptionsPreferences)
|
46
64
|
)
|
47
65
|
.returns(T.type_parameter(:Config))
|
48
66
|
end
|
49
|
-
def get_options(key, feature_names, config_class, cache_options = nil); end
|
67
|
+
def get_options(key, feature_names, config_class, cache_options = nil, preferences = nil); end
|
50
68
|
|
51
69
|
# Fetches options in JSON format based on the provided key and feature names.
|
52
70
|
#
|
@@ -55,6 +73,23 @@ module Optify
|
|
55
73
|
# @return [String] the options in JSON.
|
56
74
|
sig { params(key: String, feature_names: T::Array[String]).returns(String) }
|
57
75
|
def get_options_json(key, feature_names); end
|
76
|
+
|
77
|
+
# Fetches options in JSON format based on the provided key and feature names.
|
78
|
+
#
|
79
|
+
# @param key [String] the key to fetch options for.
|
80
|
+
# @param feature_names [Array<String>] The enabled feature names to use to build the options.
|
81
|
+
# @param preferences [GetOptionsPreferences] The preferences to use when getting options.
|
82
|
+
# @return [String] the options in JSON.
|
83
|
+
sig do
|
84
|
+
params(key: String, feature_names: T::Array[String], preferences: GetOptionsPreferences)
|
85
|
+
.returns(String)
|
86
|
+
end
|
87
|
+
def get_options_json_with_preferences(key, feature_names, preferences); end
|
88
|
+
|
89
|
+
# (Optional) Eagerly initializes the cache.
|
90
|
+
# @return [OptionsProvider] `self`.
|
91
|
+
sig { returns(OptionsProvider) }
|
92
|
+
def init; end
|
58
93
|
end
|
59
94
|
|
60
95
|
# A builder for creating an `OptionsProvider` instance.
|
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
|
+
version: 0.5.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: 2025-02-
|
11
|
+
date: 2025-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sorbet-runtime
|