foobara 0.1.10 → 0.1.11

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: 71381dfd48bd1ce8c4dd9fd71a0353753a488fd14a61525e19e240bb6d99ad62
4
- data.tar.gz: 9c0cb8f97cdee2d089ca751c6517b5af5aacd8a2e540ef974dfa23d726f17208
3
+ metadata.gz: e3d84d4d11b964a30291cd92382117fa45a7736e0ee0b6a247224427a33e6598
4
+ data.tar.gz: d1a2b86a1983b354412c1e83e2dbfc2ad259feddba8d09a01d3ef39038a27163
5
5
  SHA512:
6
- metadata.gz: 4899aec1e7f9378c8ed2e568d1c1f99c851bc505e096f742af8592be7b96fe6695282c04ca7e4edc8a8aa320c378bf734e5ad12d62b3f4e67f5cbe865d6286be
7
- data.tar.gz: d9562836258a051022093aee895099b2809e1effd77a4e0eb444c8012fb12f55e1cbd821b570069ee3bd8b7e9e8ee068195638d7df57b53308d9a057fab4f086
6
+ metadata.gz: c0c8ed8a92fbc3c1e37172881f855aa0072ffb50cd5f3c652677ddaee2af021aa937a60c2aa35d5c61f110c5b2968474b3cfaf72c593d3f9c5a405f1a3ace968
7
+ data.tar.gz: e772dc00b34a3293111f49f958c7615507c206c47f10932c461852d0b4a1ada737a9c0c5f198da11bded280aa69d1f0f383e408b241977ec3521fa5e98e76796
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [0.1.11] - 2025-09-24
2
+
3
+ - Make sure type builder caches are cleared when namespace caches are cleared
4
+ - Make sure element type resolution is performed in the right namespace
5
+ - Do not dual-purpose memoized @element_type(s) var, and memoize in IsNamespace.lru_cache instead
6
+
1
7
  # [0.1.10] - 2025-09-11
2
8
 
3
9
  - Add NotFoundError when an entity input doesn't exist
@@ -65,8 +65,6 @@ module Foobara
65
65
  def foobara_unregister(scoped)
66
66
  scoped = to_scoped(scoped)
67
67
 
68
- foobara_type_builder.clear_cache
69
-
70
68
  if scoped.is_a?(Foobara::Types::Type)
71
69
  parent_mod = nil
72
70
 
@@ -77,7 +77,7 @@ module Foobara
77
77
  if outcome.success?
78
78
  type = outcome.result
79
79
 
80
- type.element_types = :Model
80
+ type.element_types_loader = LazyElementTypes::Model
81
81
 
82
82
  model_class = type.target_class
83
83
  existing_model_type = model_class.model_type
@@ -5,11 +5,13 @@ module Foobara
5
5
  module_function
6
6
 
7
7
  def resolve(type)
8
- attributes_type_declaration = type.declaration_data[:attributes_declaration]
8
+ Namespace.use type.created_in_namespace do
9
+ attributes_type_declaration = type.declaration_data[:attributes_declaration]
9
10
 
10
- type.element_types = TypeDeclarations.strict do
11
- handler = Domain.current.foobara_type_builder.handler_for_class(Handlers::ExtendAttributesTypeDeclaration)
12
- handler.process_value!(TypeDeclaration.new(attributes_type_declaration))
11
+ type.element_types = TypeDeclarations.strict do
12
+ handler = Domain.current.foobara_type_builder.handler_for_class(Handlers::ExtendAttributesTypeDeclaration)
13
+ handler.process_value!(TypeDeclaration.new(attributes_type_declaration))
14
+ end
13
15
  end
14
16
  end
15
17
  end
@@ -5,11 +5,13 @@ module Foobara
5
5
  module IsNamespace
6
6
  class << self
7
7
  def lru_cache
8
- @lru_cache ||= Foobara::LruCache.new(100)
8
+ @lru_cache ||= Foobara::LruCache.new(200)
9
9
  end
10
10
 
11
11
  def clear_lru_cache!
12
- @lru_cache = nil
12
+ if @lru_cache
13
+ lru_cache.reset!
14
+ end
13
15
  end
14
16
  end
15
17
 
@@ -141,7 +143,7 @@ module Foobara
141
143
  LookupMode.validate!(mode)
142
144
  path = Namespace.to_registry_path(path)
143
145
 
144
- lru_cache.cached([path, mode, self, filter]) do
146
+ lru_cache.cached([self, path, mode, *filter]) do
145
147
  visited = Set.new
146
148
  foobara_lookup_without_cache(path, filter:, mode:, visited:)
147
149
  end
@@ -27,6 +27,7 @@ module Foobara
27
27
  # parent: n
28
28
  # dependent: n
29
29
  # TODO: don't we have an enumerated class/project for this?
30
+ # Maybe use bitmasks for the above 3 places to look instead of a list of 7 lookup types? (There should be 8...)
30
31
  module LookupMode
31
32
  GENERAL = :general
32
33
  RELAXED = :relaxed
@@ -8,7 +8,7 @@ module Foobara
8
8
  class ToTypeTransformer < ExtendAssociativeArrayTypeDeclaration::ToTypeTransformer
9
9
  def transform(strict_type_declaration)
10
10
  type = super
11
- type.element_type = :Array
11
+ type.element_type_loader = LazyElementTypes::Array
12
12
  type
13
13
  end
14
14
  end
@@ -10,7 +10,7 @@ module Foobara
10
10
  class ToTypeTransformer < ExtendRegisteredTypeDeclaration::ToTypeTransformer
11
11
  def transform(strict_type_declaration)
12
12
  type = super
13
- type.element_types = :Hash
13
+ type.element_types_loader = LazyElementTypes::Hash
14
14
  type
15
15
  end
16
16
  end
@@ -8,7 +8,7 @@ module Foobara
8
8
  class ToTypeTransformer < ExtendAssociativeArrayTypeDeclaration::ToTypeTransformer
9
9
  def transform(strict_type_declaration)
10
10
  type = super
11
- type.element_types = :Attributes
11
+ type.element_types_loader = LazyElementTypes::Attributes
12
12
  type
13
13
  end
14
14
  end
@@ -8,7 +8,7 @@ module Foobara
8
8
  class ToTypeTransformer < ExtendAssociativeArrayTypeDeclaration::ToTypeTransformer
9
9
  def transform(strict_type_declaration)
10
10
  type = super
11
- type.element_types = :Tuple
11
+ type.element_types_loader = LazyElementTypes::Tuple
12
12
  type
13
13
  end
14
14
  end
@@ -5,13 +5,15 @@ module Foobara
5
5
  module_function
6
6
 
7
7
  def resolve(type)
8
- element_type_declaration = type.declaration_data[:element_type_declaration]
8
+ Namespace.use type.created_in_namespace do
9
+ element_type_declaration = type.declaration_data[:element_type_declaration]
9
10
 
10
- type.element_type = if element_type_declaration
11
- TypeDeclarations.strict do
12
- Domain.current.foobara_type_from_declaration(element_type_declaration)
11
+ type.element_type = if element_type_declaration
12
+ TypeDeclarations.strict do
13
+ Domain.current.foobara_type_from_declaration(element_type_declaration)
14
+ end
13
15
  end
14
- end
16
+ end
15
17
  end
16
18
  end
17
19
  end
@@ -5,21 +5,23 @@ module Foobara
5
5
  module_function
6
6
 
7
7
  def resolve(type)
8
- type_declarations = type.declaration_data[:element_type_declarations]
8
+ Namespace.use type.created_in_namespace do
9
+ type_declarations = type.declaration_data[:element_type_declarations]
9
10
 
10
- type.element_types = if type_declarations
11
- if type_declarations.empty?
12
- {}
13
- else
14
- TypeDeclarations.strict do
15
- domain = Domain.current
11
+ type.element_types = if type_declarations
12
+ if type_declarations.empty?
13
+ {}
14
+ else
15
+ TypeDeclarations.strict do
16
+ domain = Domain.current
16
17
 
17
- type_declarations.transform_values do |attribute_declaration|
18
- domain.foobara_type_from_declaration(attribute_declaration)
18
+ type_declarations.transform_values do |attribute_declaration|
19
+ domain.foobara_type_from_declaration(attribute_declaration)
20
+ end
19
21
  end
20
22
  end
21
23
  end
22
- end
24
+ end
23
25
  end
24
26
  end
25
27
  end
@@ -7,30 +7,32 @@ module Foobara
7
7
  module_function
8
8
 
9
9
  def resolve(type)
10
- declaration_data = type.declaration_data
10
+ Namespace.use type.created_in_namespace do
11
+ declaration_data = type.declaration_data
11
12
 
12
- key_type_declaration = declaration_data[:key_type_declaration]
13
- value_type_declaration = declaration_data[:value_type_declaration]
13
+ key_type_declaration = declaration_data[:key_type_declaration]
14
+ value_type_declaration = declaration_data[:value_type_declaration]
14
15
 
15
- type.element_types = if key_type_declaration || value_type_declaration
16
- TypeDeclarations.strict do
17
- domain = Domain.current
16
+ type.element_types = if key_type_declaration || value_type_declaration
17
+ TypeDeclarations.strict do
18
+ domain = Domain.current
18
19
 
19
- key_declaration = if key_type_declaration
20
- domain.foobara_type_from_declaration(key_type_declaration)
21
- else
22
- BuiltinTypes[:duck]
23
- end
24
-
25
- value_declaration = if value_type_declaration
26
- domain.foobara_type_from_declaration(value_type_declaration)
20
+ key_declaration = if key_type_declaration
21
+ domain.foobara_type_from_declaration(key_type_declaration)
27
22
  else
28
23
  BuiltinTypes[:duck]
29
24
  end
30
25
 
31
- [key_declaration, value_declaration]
26
+ value_declaration = if value_type_declaration
27
+ domain.foobara_type_from_declaration(value_type_declaration)
28
+ else
29
+ BuiltinTypes[:duck]
30
+ end
31
+
32
+ [key_declaration, value_declaration]
33
+ end
32
34
  end
33
- end
35
+ end
34
36
  end
35
37
  end
36
38
  end
@@ -5,17 +5,19 @@ module Foobara
5
5
  module_function
6
6
 
7
7
  def resolve(type)
8
- element_type_declarations = type.declaration_data[:element_type_declarations]
8
+ Namespace.use type.created_in_namespace do
9
+ element_type_declarations = type.declaration_data[:element_type_declarations]
9
10
 
10
- type.element_types = if element_type_declarations
11
- TypeDeclarations.strict do
12
- domain = Domain.current
11
+ type.element_types = if element_type_declarations
12
+ TypeDeclarations.strict do
13
+ domain = Domain.current
13
14
 
14
- element_type_declarations.map do |element_type_declaration|
15
- domain.foobara_type_from_declaration(element_type_declaration)
15
+ element_type_declarations.map do |element_type_declaration|
16
+ domain.foobara_type_from_declaration(element_type_declaration)
17
+ end
16
18
  end
17
19
  end
18
- end
20
+ end
19
21
  end
20
22
  end
21
23
  end
@@ -129,7 +129,7 @@ module Foobara
129
129
  end
130
130
 
131
131
  def type_for_declaration(*type_declaration_bits, &block)
132
- lru_cache.cached([type_declaration_bits, block]) do
132
+ lru_cache.cached([self, *block&.object_id, *type_declaration_bits]) do
133
133
  type_for_declaration_without_cache(*type_declaration_bits, &block)
134
134
  end
135
135
  rescue NoTypeDeclarationHandlerFoundError
@@ -152,16 +152,10 @@ module Foobara
152
152
  handler.process_value!(type_declaration)
153
153
  end
154
154
 
155
- def clear_cache
156
- if @lru_cache
157
- lru_cache.reset!
158
- end
159
- end
160
-
161
155
  private
162
156
 
163
157
  def lru_cache
164
- @lru_cache ||= Foobara::LruCache.new(100)
158
+ Namespace::IsNamespace.lru_cache
165
159
  end
166
160
  end
167
161
  end
@@ -20,7 +20,9 @@ module Foobara
20
20
  :name,
21
21
  :description,
22
22
  :sensitive,
23
- :sensitive_exposed
23
+ :sensitive_exposed,
24
+ :element_type_loader,
25
+ :element_types_loader
24
26
 
25
27
  attr_reader :type_symbol,
26
28
  :casters,
@@ -44,8 +46,6 @@ module Foobara
44
46
  transformers: [],
45
47
  validators: [],
46
48
  element_processors: nil,
47
- element_type: nil,
48
- element_types: nil,
49
49
  structure_count: nil,
50
50
  processor_classes_requiring_type: nil,
51
51
  sensitive: nil,
@@ -64,9 +64,6 @@ module Foobara
64
64
  self.element_processors = [*element_processors, *base_type&.element_processors]
65
65
 
66
66
  self.structure_count = structure_count
67
- # TODO: combine these maybe with the term "children_types"?
68
- self.element_types = element_types
69
- self.element_type = element_type
70
67
  self.target_classes = Util.array(target_classes)
71
68
  self.processor_classes_requiring_type = processor_classes_requiring_type
72
69
 
@@ -95,23 +92,23 @@ module Foobara
95
92
  end
96
93
 
97
94
  def element_type
98
- type = @element_type || base_type&.element_type
99
-
100
- if type.is_a?(::Symbol)
101
- type = @element_type = TypeDeclarations::LazyElementTypes.const_get(type).resolve(self)
95
+ lru_cache.cached([self, :element_type]) do
96
+ if element_type_loader
97
+ element_type_loader.resolve(self)
98
+ else
99
+ base_type&.element_type
100
+ end
102
101
  end
103
-
104
- type
105
102
  end
106
103
 
107
104
  def element_types
108
- types = @element_types || base_type&.element_types
109
-
110
- if types.is_a?(::Symbol)
111
- types = @element_types = TypeDeclarations::LazyElementTypes.const_get(types).resolve(self)
105
+ lru_cache.cached([self, :element_types]) do
106
+ if element_types_loader
107
+ element_types_loader.resolve(self)
108
+ else
109
+ base_type&.element_types
110
+ end
112
111
  end
113
-
114
- types
115
112
  end
116
113
 
117
114
  def has_sensitive_types?
data/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Foobara
2
2
  module Version
3
- VERSION = "0.1.10".freeze
3
+ VERSION = "0.1.11".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.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi