optify-config 1.17.3-x86_64-linux → 1.17.5-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.2/optify_ruby.so +0 -0
- data/lib/optify_ruby/3.3/optify_ruby.so +0 -0
- data/lib/optify_ruby/3.4/optify_ruby.so +0 -0
- data/lib/optify_ruby/base_config.rb +3 -144
- data/lib/optify_ruby/implementation.rb +1 -1
- data/lib/optify_ruby/options_metadata.rb +3 -1
- data/lib/optify_ruby/provider_module.rb +2 -2
- data/rbi/optify.rbi +5 -26
- data/sig/optify.rbs +4 -21
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76ca75d9f4dc94d5a811cbd541b71ddd1f34ce81dcabaddf28be5b21df0985b9
|
|
4
|
+
data.tar.gz: 180fd116144308d51f2673599ba2431e731f1f22632a5007fdaf24a0e1d8b024
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b4077119ca97e26dd6679db5fd8ae23db3fa3d190adf12266bb7c848b842ec10aafa608f7ca183ab88c2ffd99bde21437e200cc9b78ffdfeaebf16bc8f4cd431
|
|
7
|
+
data.tar.gz: cf4a5e144d8e14651b75273fe582b4d880d41fa5a5eb86baed964774d2b211df55f60fef0d99dba735e1918c5b7bd08eb38f4375df60a79f3c2364e24000b232
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,159 +1,18 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require 'optify-from_hash'
|
|
4
5
|
require 'sorbet-runtime'
|
|
5
6
|
require 'tapioca'
|
|
6
7
|
|
|
7
8
|
module Optify
|
|
9
|
+
# DEPRECATED: Use `Optify::FromHashable` instead.
|
|
8
10
|
# A base class for classes from configuration files.
|
|
9
11
|
# Classes that derive from this can easily be used with `Optify::OptionsProvider.get_options`
|
|
10
12
|
# because they will have an implementation of `from_hash` that works recursively.
|
|
11
13
|
# This class is a work in progress with minimal error handling.
|
|
12
14
|
# It may be moved to another gem in the future.
|
|
13
|
-
class BaseConfig
|
|
14
|
-
extend T::Sig
|
|
15
|
-
extend T::Helpers
|
|
15
|
+
class BaseConfig < Optify::FromHashable
|
|
16
16
|
abstract!
|
|
17
|
-
|
|
18
|
-
# Create a new immutable instance of the class from a hash.
|
|
19
|
-
#
|
|
20
|
-
# This is a class method so that it can set members with private setters.
|
|
21
|
-
# @param hash The hash to create the instance from.
|
|
22
|
-
# @return The new instance.
|
|
23
|
-
#: (Hash[untyped, untyped] hash) -> instance
|
|
24
|
-
def self.from_hash(hash)
|
|
25
|
-
instance = new
|
|
26
|
-
|
|
27
|
-
hash.each do |key, value|
|
|
28
|
-
begin
|
|
29
|
-
method = instance_method(key)
|
|
30
|
-
rescue StandardError
|
|
31
|
-
raise ArgumentError, "Error converting hash to `#{name}` because of key \"#{key}\". Perhaps \"#{key}\" is not a valid attribute for `#{name}`."
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
sig = T::Utils.signature_for_method(method)
|
|
35
|
-
raise "A Sorbet signature is required for `#{name}.#{key}`." if sig.nil?
|
|
36
|
-
|
|
37
|
-
sig_return_type = sig.return_type
|
|
38
|
-
value = _convert_value(value, sig_return_type)
|
|
39
|
-
instance.instance_variable_set("@#{key}", value)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
instance.freeze
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
#: (untyped value, untyped type) -> untyped
|
|
46
|
-
def self._convert_value(value, type)
|
|
47
|
-
if type.is_a?(T::Types::Untyped)
|
|
48
|
-
# No preferred type is given, so return the value as is.
|
|
49
|
-
return value
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
return value.to_sym if type.is_a?(T::Types::Simple) && type.raw_type == Symbol
|
|
53
|
-
|
|
54
|
-
case value
|
|
55
|
-
when Array
|
|
56
|
-
# Handle `T.nilable(T::Array[...])`
|
|
57
|
-
type = type.unwrap_nilable if type.respond_to?(:unwrap_nilable)
|
|
58
|
-
inner_type = type.type
|
|
59
|
-
return value.map { |v| _convert_value(v, inner_type) }.freeze
|
|
60
|
-
when Hash
|
|
61
|
-
# Handle `T.nilable(T::Hash[...])` and `T.any(...)`.
|
|
62
|
-
# We used to use `type = type.unwrap_nilable if type.respond_to?(:unwrap_nilable)`, but it's not needed now that we handle `T.any(...)`
|
|
63
|
-
# because using `.types` works for both cases.
|
|
64
|
-
if type.respond_to?(:types)
|
|
65
|
-
# Find a type that works for the hash.
|
|
66
|
-
type.types.each do |t|
|
|
67
|
-
return _convert_hash(value, t).freeze
|
|
68
|
-
rescue StandardError
|
|
69
|
-
# Ignore and try the next type.
|
|
70
|
-
end
|
|
71
|
-
raise TypeError, "Could not convert hash: #{value} to #{type}."
|
|
72
|
-
end
|
|
73
|
-
return _convert_hash(value, type).freeze
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# It would be nice to validate that the value is of the correct type here.
|
|
77
|
-
# For example that a string is a string and an Integer is an Integer.
|
|
78
|
-
value
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
#: (Hash[untyped, untyped] hash, untyped type) -> untyped
|
|
82
|
-
def self._convert_hash(hash, type)
|
|
83
|
-
if type.respond_to?(:raw_type)
|
|
84
|
-
# There is an object for the hash.
|
|
85
|
-
# It could be a custom class, a String, or maybe something else.
|
|
86
|
-
type_for_hash = type.raw_type
|
|
87
|
-
return type_for_hash.from_hash(hash) if type_for_hash.respond_to?(:from_hash)
|
|
88
|
-
elsif type.is_a?(T::Types::TypedHash)
|
|
89
|
-
# The hash should be a hash, but the values might be objects to convert.
|
|
90
|
-
type_for_keys = type.keys
|
|
91
|
-
|
|
92
|
-
convert_key = if type_for_keys.is_a?(T::Types::Simple) && type_for_keys.raw_type == Symbol
|
|
93
|
-
lambda(&:to_sym)
|
|
94
|
-
else
|
|
95
|
-
lambda(&:itself)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
type_for_values = type.values
|
|
99
|
-
return hash.map { |k, v| [convert_key.call(k), _convert_value(v, type_for_values)] }.to_h
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
raise TypeError, "Could not convert hash #{hash} to `#{type}`."
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
private_class_method :_convert_hash, :_convert_value
|
|
106
|
-
|
|
107
|
-
# Compare this object with another object for equality.
|
|
108
|
-
# @param other The object to compare.
|
|
109
|
-
# @return [Boolean] true if the objects are equal; otherwise, false.
|
|
110
|
-
#: (untyped other) -> bool
|
|
111
|
-
def ==(other)
|
|
112
|
-
return true if other.equal?(self)
|
|
113
|
-
return false unless other.is_a?(self.class)
|
|
114
|
-
|
|
115
|
-
instance_variables.all? do |name|
|
|
116
|
-
instance_variable_get(name) == other.instance_variable_get(name)
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
# Convert this object to a Hash recursively.
|
|
121
|
-
# This is mostly the reverse operation of `from_hash`,
|
|
122
|
-
# as keys will be symbols
|
|
123
|
-
# and `from_hash` will convert strings to symbols if that's how the attribute is declared.
|
|
124
|
-
# @return [Hash] The hash representation of this object.
|
|
125
|
-
#: () -> Hash[Symbol, untyped]
|
|
126
|
-
def to_h
|
|
127
|
-
result = Hash.new(instance_variables.size)
|
|
128
|
-
|
|
129
|
-
instance_variables.each do |var_name|
|
|
130
|
-
# Remove the @ prefix to get the method name
|
|
131
|
-
method_name = var_name.to_s[1..] #: as !nil
|
|
132
|
-
value = instance_variable_get(var_name)
|
|
133
|
-
result[method_name.to_sym] = _convert_value_to_hash(value)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
result
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
private
|
|
140
|
-
|
|
141
|
-
#: (untyped value) -> untyped
|
|
142
|
-
def _convert_value_to_hash(value)
|
|
143
|
-
case value
|
|
144
|
-
when Array
|
|
145
|
-
value.map { |v| _convert_value_to_hash(v) }
|
|
146
|
-
when Hash
|
|
147
|
-
value.transform_values { |v| _convert_value_to_hash(v) }
|
|
148
|
-
when nil
|
|
149
|
-
nil
|
|
150
|
-
else
|
|
151
|
-
if value.respond_to?(:to_h)
|
|
152
|
-
value.to_h
|
|
153
|
-
else
|
|
154
|
-
value
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
17
|
end
|
|
159
18
|
end
|
|
@@ -11,7 +11,7 @@ require_relative './provider_module'
|
|
|
11
11
|
module Optify
|
|
12
12
|
# Options for caching.
|
|
13
13
|
# Only enabling or disabling caching is supported for now.
|
|
14
|
-
class CacheOptions <
|
|
14
|
+
class CacheOptions < FromHashable
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
# Provides configurations based on keys and enabled feature names.
|
|
@@ -48,7 +48,7 @@ module Optify
|
|
|
48
48
|
# @param feature_names The enabled feature names to use to build the options.
|
|
49
49
|
# @param config_class The class of the configuration to return.
|
|
50
50
|
# The class must implement `from_hash` as a class method to convert a hash to an instance of the class.
|
|
51
|
-
# It is recommended to use a class that extends `Optify::
|
|
51
|
+
# It is recommended to use a class that extends `Optify::FromHashable` because it implements `from_hash`.
|
|
52
52
|
# @param cache_options Set this if caching is desired. Only very simple caching is supported for now.
|
|
53
53
|
# @param preferences The preferences to use when getting options.
|
|
54
54
|
# @return The options.
|
|
@@ -60,7 +60,7 @@ module Optify
|
|
|
60
60
|
Kernel.raise NotImplementedError,
|
|
61
61
|
"The provided config class must implement `from_hash` as a class method
|
|
62
62
|
in order to be converted.
|
|
63
|
-
Recommended: extend `Optify::
|
|
63
|
+
Recommended: extend `Optify::FromHashable`."
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
options_json = if preferences
|
data/rbi/optify.rbi
CHANGED
|
@@ -3,45 +3,24 @@
|
|
|
3
3
|
|
|
4
4
|
# Tools for working with configurations declared in files.
|
|
5
5
|
module Optify
|
|
6
|
+
# DEPRECATED: Use `Optify::FromHashable` instead.
|
|
6
7
|
# A base class for classes from configuration files.
|
|
7
8
|
# Classes that derive from this can easily be used with `Optify::OptionsProvider.get_options`
|
|
8
9
|
# because they will have an implementation of `from_hash` that works recursively.
|
|
9
10
|
# This class is a work in progress with minimal error handling
|
|
10
11
|
# and doesn't handle certain cases such as nilable types yet.
|
|
11
12
|
# It may be moved to another gem in the future.
|
|
12
|
-
class BaseConfig
|
|
13
|
+
class BaseConfig < FromHashable
|
|
13
14
|
abstract!
|
|
14
|
-
|
|
15
|
-
# Create a new instance of the class from a hash.
|
|
16
|
-
#
|
|
17
|
-
# This is a class method that so that it can set members with private setters.
|
|
18
|
-
# @param hash The hash to create the instance from.
|
|
19
|
-
# @return The new instance.
|
|
20
|
-
sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.attached_class) }
|
|
21
|
-
def self.from_hash(hash); end
|
|
22
|
-
|
|
23
|
-
# Convert this object to a Hash recursively.
|
|
24
|
-
# This is mostly the reverse operation of `from_hash`,
|
|
25
|
-
# as keys will be symbols
|
|
26
|
-
# and `from_hash` will convert strings to symbols if that's how the attribute is declared.
|
|
27
|
-
# @return The hash representation of this object.
|
|
28
|
-
sig { returns(T::Hash[Symbol, T.untyped]) }
|
|
29
|
-
def to_h; end
|
|
30
|
-
|
|
31
|
-
# Compare this object with another object for equality.
|
|
32
|
-
# @param other The object to compare.
|
|
33
|
-
# @return [Boolean] true if the objects are equal; otherwise, false.
|
|
34
|
-
sig { params(other: T.untyped).returns(T::Boolean) }
|
|
35
|
-
def ==(other); end
|
|
36
15
|
end
|
|
37
16
|
|
|
38
17
|
# Options for caching.
|
|
39
18
|
# Only enabling or disabling caching is supported for now.
|
|
40
|
-
class CacheOptions <
|
|
19
|
+
class CacheOptions < FromHashable
|
|
41
20
|
end
|
|
42
21
|
|
|
43
22
|
# Information about a feature.
|
|
44
|
-
class OptionsMetadata <
|
|
23
|
+
class OptionsMetadata < FromHashable
|
|
45
24
|
sig { returns(T.nilable(T::Array[String])) }
|
|
46
25
|
def aliases; end
|
|
47
26
|
|
|
@@ -214,7 +193,7 @@ module Optify
|
|
|
214
193
|
# @param feature_names The enabled feature names to use to build the options.
|
|
215
194
|
# @param config_class The class of the configuration to return.
|
|
216
195
|
# The class must implement `from_hash` as a class method to convert a hash to an instance of the class.
|
|
217
|
-
# It is recommended to use a class that extends `Optify::
|
|
196
|
+
# It is recommended to use a class that extends `Optify::FromHashable` because it implements `from_hash`.
|
|
218
197
|
# @param cache_options Set this if caching is desired. Only very simple caching is supported for now.
|
|
219
198
|
# @param preferences The preferences to use when getting options.
|
|
220
199
|
# @return The options.
|
data/sig/optify.rbs
CHANGED
|
@@ -2,40 +2,23 @@
|
|
|
2
2
|
module Optify
|
|
3
3
|
end
|
|
4
4
|
|
|
5
|
+
# DEPRECATED: Use `Optify::FromHashable` instead.
|
|
5
6
|
# A base class for classes from configuration files.
|
|
6
7
|
# Classes that derive from this can easily be used with `Optify::OptionsProvider.get_options`
|
|
7
8
|
# because they will have an implementation of `from_hash` that works recursively.
|
|
8
9
|
# This class is a work in progress with minimal error handling
|
|
9
10
|
# and doesn't handle certain cases such as nilable types yet.
|
|
10
11
|
# It may be moved to another gem in the future.
|
|
11
|
-
class Optify::BaseConfig
|
|
12
|
-
# Create a new instance of the class from a hash.
|
|
13
|
-
#
|
|
14
|
-
# This is a class method that so that it can set members with private setters.
|
|
15
|
-
# @param hash The hash to create the instance from.
|
|
16
|
-
# @return The new instance.
|
|
17
|
-
def self.from_hash: (::Hash[untyped, untyped] hash) -> instance
|
|
18
|
-
|
|
19
|
-
# Convert this object to a Hash recursively.
|
|
20
|
-
# This is mostly the reverse operation of `from_hash`,
|
|
21
|
-
# as keys will be symbols
|
|
22
|
-
# and `from_hash` will convert strings to symbols if that's how the attribute is declared.
|
|
23
|
-
# @return The hash representation of this object.
|
|
24
|
-
def to_h: () -> ::Hash[Symbol, untyped]
|
|
25
|
-
|
|
26
|
-
# Compare this object with another object for equality.
|
|
27
|
-
# @param other The object to compare.
|
|
28
|
-
# @return [Boolean] true if the objects are equal; otherwise, false.
|
|
29
|
-
def ==: (untyped other) -> bool
|
|
12
|
+
class Optify::BaseConfig < FromHashable
|
|
30
13
|
end
|
|
31
14
|
|
|
32
15
|
# Options for caching.
|
|
33
16
|
# Only enabling or disabling caching is supported for now.
|
|
34
|
-
class Optify::CacheOptions <
|
|
17
|
+
class Optify::CacheOptions < FromHashable
|
|
35
18
|
end
|
|
36
19
|
|
|
37
20
|
# Information about a feature.
|
|
38
|
-
class Optify::OptionsMetadata <
|
|
21
|
+
class Optify::OptionsMetadata < FromHashable
|
|
39
22
|
def aliases: () -> ::Array[String]?
|
|
40
23
|
|
|
41
24
|
# The canonical names of features that import this one.
|
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: 1.17.
|
|
4
|
+
version: 1.17.5
|
|
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-10
|
|
11
|
+
date: 2025-11-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: sorbet-runtime
|
|
@@ -116,6 +116,7 @@ extra_rdoc_files: []
|
|
|
116
116
|
files:
|
|
117
117
|
- lib/optify.rb
|
|
118
118
|
- lib/optify_ruby/3.2/optify_ruby.so
|
|
119
|
+
- lib/optify_ruby/3.3/optify_ruby.so
|
|
119
120
|
- lib/optify_ruby/3.4/optify_ruby.so
|
|
120
121
|
- lib/optify_ruby/base_config.rb
|
|
121
122
|
- lib/optify_ruby/get_options_preferences.rb
|