optify-config 0.2.2-x86_64-linux → 0.3.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.rb +6 -4
- data/lib/optify_ruby/base_config.rb +48 -0
- data/lib/optify_ruby/implementation.rb +20 -5
- data/lib/optify_ruby/optify_ruby.so +0 -0
- data/rbi/optify.rbi +33 -5
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 315776d94257364c8eb04e7903470b47663c3ff67fdcbdc986645e9d1bf2d52e
|
4
|
+
data.tar.gz: '09b9c75f58222bc168f4f01cc950688caad14db583792d521a7a79c1b6af0847'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecb046e5c15cfdf8cc9a426f3c5fc31e24929386c951322fccdee3caa34afb54725136126934b2cf0380d22763bc6eb572eedef765af60bb7a64619e8f3d3894
|
7
|
+
data.tar.gz: b980f7c51edbd985c75e84b41900dab0e9544753a08e9aa07314c487eff7bff615df8e8cc2ce71750e2157808239487b32fe979c43f142274e0aea0b45b634fb
|
data/lib/optify.rb
CHANGED
@@ -2,10 +2,12 @@
|
|
2
2
|
# typed: strict
|
3
3
|
|
4
4
|
# The implementation to use directly Ruby and with types declared.
|
5
|
-
require_relative
|
6
|
-
|
5
|
+
require_relative 'optify_ruby/implementation'
|
7
6
|
|
8
7
|
# The implementation in Rust which redefines some methods.
|
9
8
|
# This yields some warnings, but we should redeclare the methods in Ruby to help with type checking anyway.
|
10
|
-
# Warnings about redefining methods are normal and can be ignored
|
11
|
-
|
9
|
+
# Warnings about redefining methods are normal and can be ignored
|
10
|
+
# because the implementations in Ruby are not implemented and only exist to help with type checking.
|
11
|
+
require_relative 'optify_ruby/optify_ruby'
|
12
|
+
|
13
|
+
require_relative 'optify_ruby/base_config'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'sorbet-runtime'
|
5
|
+
require 'tapioca'
|
6
|
+
|
7
|
+
module Optify
|
8
|
+
# A base class for classes from configuration files.
|
9
|
+
# Classes that derive from this can easily be used with `Optify::OptionsProvider.get_options`
|
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.
|
13
|
+
# It may be moved to another gem in the future.
|
14
|
+
class BaseConfig
|
15
|
+
extend T::Sig
|
16
|
+
extend T::Helpers
|
17
|
+
abstract!
|
18
|
+
|
19
|
+
# Create a new instance of the class from a hash.
|
20
|
+
#
|
21
|
+
# @param hash [Hash] The hash to create the instance from.
|
22
|
+
# @return The new instance.
|
23
|
+
sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.attached_class) }
|
24
|
+
def self.from_hash(hash)
|
25
|
+
result = new
|
26
|
+
|
27
|
+
hash.each do |key, value|
|
28
|
+
# TODO: Might need some error handling here, but it should be fine if type signatures are used.
|
29
|
+
# TODO Handle nilable types.
|
30
|
+
case value
|
31
|
+
when Array
|
32
|
+
sig_return_type = T::Utils.signature_for_method(instance_method(key)).return_type
|
33
|
+
inner_type = sig_return_type.type.raw_type
|
34
|
+
value = value.map { |v| inner_type.from_hash(v) } if inner_type.respond_to?(:from_hash)
|
35
|
+
when Hash
|
36
|
+
sig_return_type = T::Utils.signature_for_method(instance_method(key)).return_type
|
37
|
+
if sig_return_type.respond_to?(:raw_type)
|
38
|
+
type_for_key = sig_return_type.raw_type
|
39
|
+
value = type_for_key.from_hash(value) if type_for_key.respond_to?(:from_hash)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
result.instance_variable_set("@#{key}", value)
|
44
|
+
end
|
45
|
+
result
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -27,11 +27,26 @@ module Optify
|
|
27
27
|
#
|
28
28
|
# @param key [String] the key to fetch options for.
|
29
29
|
# @param feature_names [Array<String>] The enabled feature names to use to build the options.
|
30
|
-
# @
|
31
|
-
|
32
|
-
|
30
|
+
# @param config_class [ConfigType] The class of the configuration to return.
|
31
|
+
# It is recommended to use a class that extends `Optify::BaseConfig` because it implements `from_hash`.
|
32
|
+
# @return [ConfigType] The options.
|
33
|
+
sig do
|
34
|
+
type_parameters(:Config)
|
35
|
+
.params(
|
36
|
+
key: String,
|
37
|
+
feature_names: T::Array[String],
|
38
|
+
config_class: T::Class[T.type_parameter(:Config)]
|
39
|
+
)
|
40
|
+
.returns(T.type_parameter(:Config))
|
41
|
+
end
|
42
|
+
def get_options(key, feature_names, config_class)
|
33
43
|
options_json = get_options_json(key, feature_names)
|
34
|
-
JSON.parse(options_json, object_class:
|
44
|
+
h = JSON.parse(options_json, object_class: Hash)
|
45
|
+
unless config_class.respond_to?(:from_hash)
|
46
|
+
raise NotImplementedError, 'The provided config class does not implement to `from_hash`.'
|
47
|
+
end
|
48
|
+
|
49
|
+
T.unsafe(config_class).from_hash(h)
|
35
50
|
end
|
36
51
|
end
|
37
52
|
|
@@ -56,4 +71,4 @@ module Optify
|
|
56
71
|
raise NotImplementedError
|
57
72
|
end
|
58
73
|
end
|
59
|
-
end
|
74
|
+
end
|
Binary file
|
data/rbi/optify.rbi
CHANGED
@@ -1,16 +1,44 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: strong
|
2
3
|
|
3
4
|
# Tools for working with configurations declared in files.
|
4
5
|
module Optify
|
6
|
+
# A base class for classes from configuration files.
|
7
|
+
# Classes that derive from this can easily be used with `Optify::OptionsProvider.get_options`
|
8
|
+
# because they will have an implementation of `from_hash` that works recursively.
|
9
|
+
# This class is a work in progress with minimal error handling
|
10
|
+
# and doesn't handle certain cases such as nilable types yet.
|
11
|
+
# It may be moved to another gem in the future.
|
12
|
+
class BaseConfig
|
13
|
+
abstract!
|
14
|
+
|
15
|
+
# Create a new instance of the class from a hash.
|
16
|
+
#
|
17
|
+
# @param hash [Hash] The hash to create the instance from.
|
18
|
+
# @return The new instance.
|
19
|
+
sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.attached_class) }
|
20
|
+
def self.from_hash(hash); end
|
21
|
+
end
|
22
|
+
|
5
23
|
# Provides configurations based on keys and enabled feature names.
|
6
24
|
class OptionsProvider
|
7
25
|
# Fetches options based on the provided key and feature names.
|
8
26
|
#
|
9
27
|
# @param key [String] the key to fetch options for.
|
10
28
|
# @param feature_names [Array<String>] The enabled feature names to use to build the options.
|
11
|
-
# @
|
12
|
-
|
13
|
-
|
29
|
+
# @param config_class [ConfigType] The class of the configuration to return.
|
30
|
+
# It is recommended to use a class that extends `Optify::BaseConfig` because it implements `from_hash`.
|
31
|
+
# @return [ConfigType] The options.
|
32
|
+
sig do
|
33
|
+
type_parameters(:Config)
|
34
|
+
.params(
|
35
|
+
key: String,
|
36
|
+
feature_names: T::Array[String],
|
37
|
+
config_class: T::Class[T.type_parameter(:Config)]
|
38
|
+
)
|
39
|
+
.returns(T.type_parameter(:Config))
|
40
|
+
end
|
41
|
+
def get_options(key, feature_names, config_class); end
|
14
42
|
|
15
43
|
# Fetches options in JSON format based on the provided key and feature names.
|
16
44
|
#
|
@@ -34,4 +62,4 @@ module Optify
|
|
34
62
|
sig { returns(OptionsProvider) }
|
35
63
|
def build; end
|
36
64
|
end
|
37
|
-
end
|
65
|
+
end
|
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.3.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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sorbet-runtime
|
@@ -80,14 +80,16 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 3.6.7
|
83
|
-
description:
|
84
|
-
|
83
|
+
description: |-
|
84
|
+
Simplifies getting the right configuration options for a process using pre-loaded configurations
|
85
|
+
from files to manage options for experiments or flights.
|
85
86
|
email:
|
86
87
|
executables: []
|
87
88
|
extensions: []
|
88
89
|
extra_rdoc_files: []
|
89
90
|
files:
|
90
91
|
- lib/optify.rb
|
92
|
+
- lib/optify_ruby/base_config.rb
|
91
93
|
- lib/optify_ruby/implementation.rb
|
92
94
|
- lib/optify_ruby/optify_ruby.so
|
93
95
|
- rbi/optify.rbi
|