foobara 0.5.4 → 0.5.5

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: a96afa4b186236cc708db3bc2a292756816db8e601a5cef7b31d0082a4a97dea
4
- data.tar.gz: f184bf52340442842d0e6d9bdaa0f50a7c3a7f07421d4bb4a1c776c634703e4e
3
+ metadata.gz: 6527e62790180b1aeb2f98e069655d8ac72750fbff834fc63e9b75a01c35cb4e
4
+ data.tar.gz: a769dd2a642b71bd401dabe3c0917a1fa128069f2a7987ff79df633765ae93ad
5
5
  SHA512:
6
- metadata.gz: 3c2fa3e1b90cc5f6f31df05683b17fef4ef7ad77c07c5af9190a603696b4470355b357f726dcef2f05dbbdf79213c56e655578a3731f9e03cd25397c4d0fb62e
7
- data.tar.gz: 7b832dba231c05086a83d0a56fc799910bcee15fae5c3979eac8923d1f1bd17064d759dc9d0c0b94456400a92e2243d93b942822af16fd1b5f12b3b6c6b479e5
6
+ metadata.gz: '0359999dd32f56220e88e3e860ff7e415a4fd2b978bf83768868b1e10b0013c9e02597731890d1a2abb2fd11c1e288e1c1e8056b3bd6bf7a11bc9589af371ae3'
7
+ data.tar.gz: 33cf7a4428854d3016c1ccda045820e6da47a268e34f5bb05505bcc878ecdeff909caf1c411505d97849f4ffd69cc6e9c1c51a046ee92f6ee7ac2afe1919b359
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [0.5.5] - 2026-02-19
2
+
3
+ - Fix bug where WeakObjectSet#delete could fail after deactivation
4
+ - Fix bug where arrays of allowed rules run in the wrong context
5
+ - Remove awkward proc defaults from manifest
6
+
1
7
  # [0.5.4] - 2026-02-16
2
8
 
3
9
  - Fix bug where adding a desugarizer to a subclass had no effect
@@ -60,16 +60,17 @@ module Foobara
60
60
  possible_errors:,
61
61
  depends_on:,
62
62
  # TODO: allow inputs type to be nil or really any type?
63
- inputs_type: inputs_type&.reference_or_declaration_data || GlobalDomain.foobara_type_from_declaration(
64
- type: "::attributes",
65
- element_type_declarations: {},
66
- required: []
67
- ).declaration_data
63
+ inputs_type: inputs_type&.reference_or_declaration_data_for_manifest ||
64
+ GlobalDomain.foobara_type_from_declaration(
65
+ type: "::attributes",
66
+ element_type_declarations: {},
67
+ required: []
68
+ ).declaration_data
68
69
  ).merge(description:)
69
70
 
70
71
  if result_type
71
72
  # TODO: find a way to represent literal types like "nil"
72
- h[:result_type] = result_type.reference_or_declaration_data
73
+ h[:result_type] = result_type.reference_or_declaration_data_for_manifest
73
74
  end
74
75
 
75
76
  super.merge(h)
@@ -263,7 +263,7 @@ module Foobara
263
263
  procs = rules.map(&:block)
264
264
 
265
265
  block = proc do
266
- procs.any?(&:call)
266
+ procs.any? { |p| instance_exec(&p) }
267
267
  end
268
268
 
269
269
  allowed_rule = AllowedRule.new(&block)
@@ -381,7 +381,7 @@ module Foobara
381
381
  end
382
382
 
383
383
  # TODO: This should support nil as an inputs_type but it breaks other projects for now
384
- inputs_type = inputs_type_for_manifest&.reference_or_declaration_data ||
384
+ inputs_type = inputs_type_for_manifest&.reference_or_declaration_data_for_manifest ||
385
385
  { type: :attributes, element_type_declarations: {} }
386
386
 
387
387
  # TODO: handle errors_types_depended_on!
@@ -390,7 +390,7 @@ module Foobara
390
390
  result_types_depended_on:,
391
391
  types_depended_on: types,
392
392
  inputs_type:,
393
- result_type: result_type&.reference_or_declaration_data,
393
+ result_type: result_type&.reference_or_declaration_data_for_manifest,
394
394
  possible_errors: possible_errors_manifest,
395
395
  capture_unknown_error:,
396
396
  inputs_transformers:,
@@ -45,7 +45,7 @@ module Foobara
45
45
  loop do
46
46
  object_id = queue.pop
47
47
  if object_id
48
- weak_object_set.delete(object_id)
48
+ weak_object_set&.delete(object_id)
49
49
  elsif queue.closed?
50
50
  self.queue = nil
51
51
  break
@@ -420,6 +420,10 @@ module Foobara
420
420
  scoped_full_name
421
421
  end
422
422
 
423
+ def reference_or_declaration_data_for_manifest
424
+ reference_or_declaration_data(declaration_data_for_manifest)
425
+ end
426
+
423
427
  def reference_or_declaration_data(declaration_data = self.declaration_data)
424
428
  remove_sensitive = TypeDeclarations.foobara_manifest_context_remove_sensitive?
425
429
 
@@ -437,6 +441,30 @@ module Foobara
437
441
  end
438
442
  end
439
443
 
444
+ def declaration_data_for_manifest
445
+ data = declaration_data
446
+
447
+ if data.is_a?(::Hash) && data[:type] == :attributes
448
+ if data.key?(:defaults)
449
+ defaults = data[:defaults]
450
+
451
+ if defaults.is_a?(::Hash) && defaults.values.any? { it.is_a?(Proc) }
452
+ cleaned_defaults = defaults.transform_values do |value|
453
+ if value.is_a?(Proc)
454
+ "[<Lazily Set>]"
455
+ else
456
+ value
457
+ end
458
+ end
459
+
460
+ data = data.merge(defaults: cleaned_defaults)
461
+ end
462
+ end
463
+ end
464
+
465
+ data
466
+ end
467
+
440
468
  # TODO: put this somewhere else
441
469
  def foobara_manifest_reference
442
470
  scoped_full_name
@@ -462,7 +490,7 @@ module Foobara
462
490
  [possible_error.key.to_s, possible_error.foobara_manifest]
463
491
  end.sort.to_h
464
492
 
465
- declaration_data = self.declaration_data
493
+ declaration_data = declaration_data_for_manifest
466
494
 
467
495
  if remove_sensitive
468
496
  declaration_data = TypeDeclarations.remove_sensitive_types(declaration_data)
@@ -1,4 +1,6 @@
1
1
  RSpec.describe Foobara::BuiltinTypes::Attributes do
2
+ after { Foobara.reset_alls }
3
+
2
4
  let(:type) {
3
5
  Foobara::Domain.current.foobara_type_from_declaration(type_declaration)
4
6
  }
@@ -61,6 +63,26 @@ RSpec.describe Foobara::BuiltinTypes::Attributes do
61
63
  end
62
64
  end
63
65
 
66
+ context "when default is a proc" do
67
+ let(:type_declaration) do
68
+ {
69
+ type: :attributes,
70
+ element_type_declarations: {
71
+ a: :integer,
72
+ b: :integer
73
+ },
74
+ defaults: { a: -> { 10 }, b: 100 }
75
+ }
76
+ end
77
+
78
+ it "applies defaults and scrubs the value in the manifest data" do
79
+ expect(type.process_value!({})).to eq(a: 10, b: 100)
80
+
81
+ Foobara::GlobalDomain.foobara_register_type(:some_type, type)
82
+ expect(type.foobara_manifest[:declaration_data][:defaults]).to eq(a: "[<Lazily Set>]", b: 100)
83
+ end
84
+ end
85
+
64
86
  context "when defaults contains invalid attribute names" do
65
87
  let(:type_declaration) do
66
88
  {
data/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Foobara
2
2
  module Version
3
- VERSION = "0.5.4".freeze
3
+ VERSION = "0.5.5".freeze
4
4
  MINIMUM_RUBY_VERSION = ">= 3.4.0".freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi