optify-config 1.11.0 → 1.12.0

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: 5c469a50d682d32a3452f845f8aff3d94ff3211d633f8cc3801ff5e6ed20bb24
4
- data.tar.gz: 9a25f828047becf5aebfccac21065828785b66c3af5549e68b408a7215294836
3
+ metadata.gz: f165ec3b9287043a5f65b8b9c0f3d6781a75e38ca4246da3deda8672162f33b5
4
+ data.tar.gz: 8159794d6a5965c89e488b46f2b6eb2aaf21fed54fad389418a340ab43d65c36
5
5
  SHA512:
6
- metadata.gz: edc4a41fed55115e3f2ef51a1c67c4012a764c8880dc51d900043d7a699ecbdcafdd95f91a560815721467f2aee73d18040e9ab8e9790ec3da2c423626c586e6
7
- data.tar.gz: 8c2c4845aea3cdeb8b7a345a41e1a9605d6262b0b3631f838ae703e6bc98103348f2bf52f9d847437dfe040fda9f97a7715962b876c32c80bcd3c76ed30c93a1
6
+ metadata.gz: 7611a2a9e75d7316d5f1b0902c566f6fdadc8887c6d04d1dab58c953a06d05412d58c618a2c18937e99d959e2b9e009cfe86cba03d615dacf5ab191f13dbbf17
7
+ data.tar.gz: ed1afa3d234131b4c020551ee84ab11c68f1e4eaf215400561202efe7fc3126364d4129cdc8ca83c2d7ec67f6291de7a7e15bbbed395cd57ea861a218cd5ea6d
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "optify_ruby"
3
- version = "0.13.0"
3
+ version = "0.14.0"
4
4
  edition = "2021"
5
5
 
6
6
  description = "optify bindings for Ruby"
@@ -21,6 +21,6 @@ crate-type = ["cdylib"]
21
21
 
22
22
  [dependencies]
23
23
  magnus = "0.7.1"
24
- optify = { path = "../../../../rust/optify", version = "0.13.0" }
24
+ optify = { path = "../../../../rust/optify", version = "0.14.0" }
25
25
  rb-sys = { version = "*", default-features = false, features = ["ruby-static"] }
26
26
  serde_json = "1.0.140"
@@ -10,6 +10,12 @@ use optify::schema::metadata::OptionsMetadata;
10
10
  use std::cell::RefCell;
11
11
  use std::path::Path;
12
12
 
13
+ fn convert_preferences(
14
+ preferences: &MutGetOptionsPreferences,
15
+ ) -> std::cell::Ref<'_, GetOptionsPreferences> {
16
+ preferences.0.borrow()
17
+ }
18
+
13
19
  #[derive(Clone)]
14
20
  #[wrap(class = "Optify::GetOptionsPreferences")]
15
21
  struct MutGetOptionsPreferences(RefCell<GetOptionsPreferences>);
@@ -17,11 +23,27 @@ struct MutGetOptionsPreferences(RefCell<GetOptionsPreferences>);
17
23
  impl MutGetOptionsPreferences {
18
24
  fn new() -> Self {
19
25
  Self(RefCell::new(GetOptionsPreferences {
26
+ constraints: None,
20
27
  overrides_json: None,
21
28
  skip_feature_name_conversion: false,
22
29
  }))
23
30
  }
24
31
 
32
+ // Constraints Section
33
+ fn set_constraints_json(&self, constraints_json: Option<String>) {
34
+ self.0
35
+ .borrow_mut()
36
+ .set_constraints_json(constraints_json.as_deref());
37
+ }
38
+
39
+ fn get_constraints_json(&self) -> Option<String> {
40
+ self.0
41
+ .borrow()
42
+ .constraints
43
+ .as_ref()
44
+ .map(|c| serde_json::to_string(&c.constraints).unwrap())
45
+ }
46
+
25
47
  // Overrides Section
26
48
  fn has_overrides(&self) -> bool {
27
49
  self.0.borrow().overrides_json.is_some()
@@ -86,11 +108,11 @@ impl WrappedOptionsProvider {
86
108
  feature_names: Vec<String>,
87
109
  preferences: &MutGetOptionsPreferences,
88
110
  ) -> Result<String, magnus::Error> {
89
- let preferences = convert_preferences(preferences);
111
+ let preferences = &convert_preferences(preferences);
90
112
  match rb_self
91
113
  .0
92
114
  .borrow()
93
- .get_all_options(&feature_names, None, Some(&preferences))
115
+ .get_all_options(&feature_names, None, Some(preferences))
94
116
  {
95
117
  Ok(options) => Ok(options.to_string()),
96
118
  Err(e) => Err(magnus::Error::new(ruby.exception_runtime_error(), e)),
@@ -161,12 +183,12 @@ impl WrappedOptionsProvider {
161
183
  feature_names: Vec<String>,
162
184
  preferences: &MutGetOptionsPreferences,
163
185
  ) -> Result<String, magnus::Error> {
164
- let preferences = convert_preferences(preferences);
186
+ let preferences = &convert_preferences(preferences);
165
187
  match rb_self.0.borrow().get_options_with_preferences(
166
188
  &key,
167
189
  &feature_names,
168
190
  None,
169
- Some(&preferences),
191
+ Some(preferences),
170
192
  ) {
171
193
  Ok(options) => Ok(options.to_string()),
172
194
  Err(e) => Err(magnus::Error::new(ruby.exception_runtime_error(), e)),
@@ -174,13 +196,6 @@ impl WrappedOptionsProvider {
174
196
  }
175
197
  }
176
198
 
177
- fn convert_preferences(preferences: &MutGetOptionsPreferences) -> GetOptionsPreferences {
178
- GetOptionsPreferences {
179
- overrides_json: preferences.get_overrides_json(),
180
- skip_feature_name_conversion: preferences.skip_feature_name_conversion(),
181
- }
182
- }
183
-
184
199
  #[derive(Clone)]
185
200
  #[wrap(class = "Optify::OptionsProviderBuilder")]
186
201
  struct WrappedOptionsProviderBuilder(RefCell<OptionsProviderBuilder>);
@@ -245,11 +260,11 @@ impl WrappedOptionsWatcher {
245
260
  feature_names: Vec<String>,
246
261
  preferences: &MutGetOptionsPreferences,
247
262
  ) -> Result<String, magnus::Error> {
248
- let preferences = convert_preferences(preferences);
263
+ let preferences = &convert_preferences(preferences);
249
264
  match rb_self
250
265
  .0
251
266
  .borrow()
252
- .get_all_options(&feature_names, None, Some(&preferences))
267
+ .get_all_options(&feature_names, None, Some(preferences))
253
268
  {
254
269
  Ok(options) => Ok(options.to_string()),
255
270
  Err(e) => Err(magnus::Error::new(ruby.exception_runtime_error(), e)),
@@ -318,12 +333,12 @@ impl WrappedOptionsWatcher {
318
333
  feature_names: Vec<String>,
319
334
  preferences: &MutGetOptionsPreferences,
320
335
  ) -> Result<String, magnus::Error> {
321
- let preferences = convert_preferences(preferences);
336
+ let preferences = &convert_preferences(preferences);
322
337
  match rb_self.0.borrow().get_options_with_preferences(
323
338
  &key,
324
339
  &feature_names,
325
340
  None,
326
- Some(&preferences),
341
+ Some(preferences),
327
342
  ) {
328
343
  Ok(options) => Ok(options.to_string()),
329
344
  Err(e) => Err(magnus::Error::new(ruby.exception_runtime_error(), e)),
@@ -423,6 +438,14 @@ fn init(ruby: &Ruby) -> Result<(), magnus::Error> {
423
438
 
424
439
  let get_options_preferences_class =
425
440
  module.define_class("GetOptionsPreferences", ruby.class_object())?;
441
+ get_options_preferences_class.define_method(
442
+ "constraints_json=",
443
+ method!(MutGetOptionsPreferences::set_constraints_json, 1),
444
+ )?;
445
+ get_options_preferences_class.define_method(
446
+ "constraints_json",
447
+ method!(MutGetOptionsPreferences::get_constraints_json, 0),
448
+ )?;
426
449
  get_options_preferences_class
427
450
  .define_singleton_method("new", function!(MutGetOptionsPreferences::new, 0))?;
428
451
  get_options_preferences_class
@@ -435,6 +458,10 @@ fn init(ruby: &Ruby) -> Result<(), magnus::Error> {
435
458
  "overrides_json=",
436
459
  method!(MutGetOptionsPreferences::set_overrides_json, 1),
437
460
  )?;
461
+ get_options_preferences_class.define_method(
462
+ "overrides_json",
463
+ method!(MutGetOptionsPreferences::get_overrides_json, 0),
464
+ )?;
438
465
  get_options_preferences_class.define_method(
439
466
  "skip_feature_name_conversion=",
440
467
  method!(
@@ -4,6 +4,12 @@
4
4
  module Optify
5
5
  # Preferences for `get_options`.
6
6
  class GetOptionsPreferences
7
+ # @param constraints [Hash]
8
+ #: (Hash[untyped, untyped] constraints) -> void
9
+ def constraints=(constraints)
10
+ self.constraints_json = constraints.to_json
11
+ end
12
+
7
13
  # @param overrides [Hash]
8
14
  #: (Hash[untyped, untyped] overrides) -> void
9
15
  def overrides=(overrides)
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  # typed: strict
3
3
 
4
- require 'json'
5
-
6
4
  require 'sorbet-runtime'
7
5
 
8
6
  require_relative './base_config'
@@ -95,7 +95,7 @@ module Optify
95
95
  init unless @cache
96
96
  feature_names = get_canonical_feature_names(feature_names) unless preferences&.skip_feature_name_conversion
97
97
 
98
- cache_key = [key, feature_names, config_class]
98
+ cache_key = [key, feature_names, preferences&.constraints_json, config_class]
99
99
  result = @cache&.fetch(cache_key, NOT_FOUND_IN_CACHE_SENTINEL)
100
100
  return result unless result.equal?(NOT_FOUND_IN_CACHE_SENTINEL)
101
101
 
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  # typed: strict
3
3
 
4
- require 'json'
5
-
6
4
  require 'sorbet-runtime'
7
5
 
8
6
  require_relative './base_config'
data/rbi/optify.rbi CHANGED
@@ -49,6 +49,16 @@ module Optify
49
49
 
50
50
  # Preferences when getting options.
51
51
  class GetOptionsPreferences
52
+ # Set constraints for the current request to limit the features that can be enabled.
53
+ sig { params(value: T.nilable(T::Hash[T.untyped, T.untyped])).void }
54
+ def constraints=(value); end
55
+
56
+ sig { params(value: T.nilable(String)).void }
57
+ def constraints_json=(value); end
58
+
59
+ sig { returns(T.nilable(String)) }
60
+ def constraints_json; end
61
+
52
62
  # Indicates if overrides are set.
53
63
  sig { returns(T::Boolean) }
54
64
  def overrides?; end
@@ -65,6 +75,9 @@ module Optify
65
75
  sig { params(value: T.nilable(String)).void }
66
76
  def overrides_json=(value); end
67
77
 
78
+ sig { returns(T.nilable(String)) }
79
+ def overrides_json; end
80
+
68
81
  sig { params(value: T::Boolean).void }
69
82
  def skip_feature_name_conversion=(value); end
70
83
 
@@ -82,13 +95,13 @@ module Optify
82
95
  # Build using just one directory.
83
96
  # @param directory The directory to build the provider from.
84
97
  # @return The instance.
85
- sig { params(directory: String).returns(OptionsRegistry) }
98
+ sig { params(directory: String).returns(T.attached_class) }
86
99
  def build(directory); end
87
100
 
88
101
  # Build from multiple directories.
89
102
  # @param directories The directories to build the provider from.
90
103
  # @return The instance.
91
- sig { params(directories: T::Array[String]).returns(OptionsRegistry) }
104
+ sig { params(directories: T::Array[String]).returns(T.attached_class) }
92
105
  def build_from_directories(directories); end
93
106
  end
94
107
 
data/sig/optify.rbs CHANGED
@@ -40,6 +40,13 @@ end
40
40
 
41
41
  # Preferences when getting options.
42
42
  class Optify::GetOptionsPreferences
43
+ # Set constraints for the current request to limit the features that can be enabled.
44
+ def constraints=: (::Hash[untyped, untyped]? value) -> void
45
+
46
+ def constraints_json=: (String? value) -> void
47
+
48
+ def constraints_json: () -> String?
49
+
43
50
  # Indicates if overrides are set.
44
51
  def overrides?: () -> bool
45
52
 
@@ -53,6 +60,8 @@ class Optify::GetOptionsPreferences
53
60
  # @param value The overrides to apply as serialized JSON.
54
61
  def overrides_json=: (String? value) -> void
55
62
 
63
+ def overrides_json: () -> String?
64
+
56
65
  def skip_feature_name_conversion=: (bool value) -> void
57
66
 
58
67
  def skip_feature_name_conversion: () -> bool
@@ -65,12 +74,12 @@ class Optify::OptionsRegistry
65
74
  # Build using just one directory.
66
75
  # @param directory The directory to build the provider from.
67
76
  # @return The instance.
68
- def build: (String directory) -> OptionsRegistry
77
+ def build: (String directory) -> instance
69
78
 
70
79
  # Build from multiple directories.
71
80
  # @param directories The directories to build the provider from.
72
81
  # @return The instance.
73
- def build_from_directories: (::Array[String] directories) -> OptionsRegistry
82
+ def build_from_directories: (::Array[String] directories) -> instance
74
83
 
75
84
  # @return All of the aliases.
76
85
  def aliases: () -> ::Array[String]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optify-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin D. Harris
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-07-04 00:00:00.000000000 Z
10
+ date: 2025-07-08 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rb_sys