optify-config 0.4.6-aarch64-linux → 0.5.0-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44f5a5d6197f5d36b99efdf187d48ea186bc47b45a68c4f8c07781f1fc1b1919
4
- data.tar.gz: 785fd1a53790d5147bf1ca0139fb10fc162267cb1c391230c4019079c629d5c8
3
+ metadata.gz: 86b1b6a0724c23d2c5bf72e6835d9523dd36cc80919bbefa484b3c6a86f59ce3
4
+ data.tar.gz: 4fa13d99ea25b46d0790ab435bf3d256653a55a513dc6150cd447341135e8bf6
5
5
  SHA512:
6
- metadata.gz: c6b294ef55d0d8b7947f67cd8c70c6a730d3eaccf687a7f9e37e541d288aa4ec4f0074e0c9def1ebc9e63f06d90860fb1e353c57cad8d38eadb3e95cbbc0d0c3
7
- data.tar.gz: 45ea42b24324f9c2113c528ef8c38b7b509d49bac30cfe1117d2a73b3a2e9f5f7f6dfb89d4062a9679fef238e58d604ff5e9a18e017e942168055870957a51d6
6
+ metadata.gz: df5f70f4962e3b8abb98da20b5b2099986a5e9c27fd31b45afb9d29f92ec331f9481760d8e622a72a80115bbcb605e88726cc9af5e4f97c3a1386c036c37fe25
7
+ data.tar.gz: 7970abf30ceb3c97a20ee0468ccc0fa41142403fe7ad0eed467ef26238a6787d907714c73c90f31a49be82848b76d6695345fb209542e42ffa8730163cabbfb1
Binary file
Binary file
Binary file
@@ -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 = get_options_json(key, feature_names)
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,24 +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
- # TODO: Consider aliases when caching. Right now, they are only visible in Rust
73
- # and we don't want the cache in Rust because we won't to avoid any conversion overhead.
74
- @cache ||= T.let({}, T.nilable(T::Hash[T.untyped, T.untyped]))
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.fetch(cache_key, NOT_FOUND_IN_CACHE_SENTINEL)
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
- result = get_options(key, feature_names, config_class)
96
+ preferences ||= GetOptionsPreferences.new
97
+ preferences.skip_feature_name_conversion = true
98
+ result = get_options(key, feature_names, config_class, nil, preferences)
80
99
 
81
- @cache[cache_key] = result
100
+ T.must(@cache)[cache_key] = result
82
101
  end
83
102
  end
84
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.6
4
+ version: 0.5.0
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-12 00:00:00.000000000 Z
11
+ date: 2025-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sorbet-runtime