foobara 0.0.52 → 0.0.53

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69f568d4dcdb081e50f321e36b9805621229ea6c48305cc5c15d5b352323015b
4
- data.tar.gz: 4f4129cc01d8ef7cdb81c68f9a310641e022c5ca22ae2c394854e8053e46365c
3
+ metadata.gz: 6f36fa530b7c550b95ee9f580590ad68e18700e80048746fb734078ea0e9744e
4
+ data.tar.gz: 1454b5d06e3be5c3be8b9cfee10b6e598b71ad74f409c7f09d2a66427f71f3a7
5
5
  SHA512:
6
- metadata.gz: f8561097b379dbb98e1cc082fa6b1fb02f5d0b2cb1923c0b9360bd9e7a552cb484c305af77cde237a5fadebecdc518b75189885e01e2b2e8b7974f771ea738b9
7
- data.tar.gz: 9568912e55c1c1593adf41143a5fd1f577d72b66e50ed69b4bf99ad4a00b3a1d048272187039904fade1a18032008547749f72fdf9b9ed8533a7fff7ffeeb998
6
+ metadata.gz: 5a238d0b3ba1366f67a0edee344a7f0228367b56a0c45eabe230603310a4b36b9f13b765382907a9e8c72533f0ec18af6f1b956e575a0c79bffe08e036de3097
7
+ data.tar.gz: 99b3b4c279bc4104fc1faefda279bf4fadcae8ee57975655dec120f17ce5980fda6b2dccf1476e00df20460e3a091dba56f5c00afdc4907bdf62c374feddee78
data/CHANGELOG.md CHANGED
@@ -1,6 +1,7 @@
1
- ## [0.0.52] - 2025-01-30
1
+ ## [0.0.53] - 2025-01-30
2
2
 
3
3
  - Prefix and re-organize several model methods to facilitate type extension
4
+ - Add support for generating a manifest with detached entities based on context
4
5
 
5
6
  ## [0.0.51] - 2025-01-26
6
7
 
@@ -0,0 +1,63 @@
1
+ module Foobara
2
+ class DetachedEntityType < Types::Type
3
+ class << self
4
+ def types_requiring_conversion
5
+ @types_requiring_conversion ||= Set.new
6
+ end
7
+
8
+ def model_base_classes_requiring_conversion
9
+ @model_base_classes_requiring_conversion ||= Set.new
10
+ end
11
+
12
+ def type_requires_conversion?(type)
13
+ types_requiring_conversion.include?(type)
14
+ end
15
+
16
+ def model_base_class_requires_conversion?(model_base_class)
17
+ model_base_classes_requiring_conversion.include?(model_base_class)
18
+ end
19
+ end
20
+
21
+ def foobara_manifest(to_include: Set.new)
22
+ manifest = super
23
+
24
+ if detached_context?
25
+ declaration_data = manifest[:declaration_data]
26
+ if self.class.type_requires_conversion?(declaration_data[:type])
27
+ declaration_data = declaration_data.merge(type: :detached_entity)
28
+ end
29
+
30
+ if self.class.model_base_class_requires_conversion?(declaration_data[:model_base_class])
31
+ declaration_data = declaration_data.merge(model_base_class: "Foobara::DetachedEntity")
32
+ end
33
+
34
+ manifest = manifest.merge(declaration_data:)
35
+ end
36
+
37
+ manifest
38
+ end
39
+
40
+ def types_to_add_to_manifest
41
+ types = super
42
+
43
+ if detached_context?
44
+ types.delete(base_type)
45
+ types.unshift(base_type_for_manifest)
46
+ end
47
+
48
+ types
49
+ end
50
+
51
+ def base_type_for_manifest
52
+ if detached_context?
53
+ BuiltinTypes[:detached_entity]
54
+ else
55
+ super
56
+ end
57
+ end
58
+
59
+ def detached_context?
60
+ Thread.foobara_var_get("foobara_manifest_context")&.[](:detached)
61
+ end
62
+ end
63
+ end
@@ -20,6 +20,10 @@ module Foobara
20
20
  end
21
21
  end
22
22
  end
23
+
24
+ def type_class
25
+ Foobara::DetachedEntityType
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -11,6 +11,9 @@ module Foobara
11
11
 
12
12
  detached_entity = Namespace.global.foobara_lookup_type!(:detached_entity)
13
13
  BuiltinTypes.build_and_register!(:entity, detached_entity, nil)
14
+
15
+ DetachedEntityType.types_requiring_conversion << :entity
16
+ DetachedEntityType.model_base_classes_requiring_conversion << "Foobara::Entity"
14
17
  end
15
18
 
16
19
  def reset_all
@@ -53,6 +53,7 @@ module Foobara
53
53
  end
54
54
 
55
55
  def model?
56
+ # TODO: hmmmm, should be false for :active_record
56
57
  return false if %w[entity detached_entity].include?(reference)
57
58
 
58
59
  type = base_type
@@ -19,6 +19,10 @@ class Thread
19
19
  def foobara_var_set(...)
20
20
  Thread.current.foobara_var_set(...)
21
21
  end
22
+
23
+ def foobara_with_var(...)
24
+ Thread.current.foobara_with_var(...)
25
+ end
22
26
  end
23
27
 
24
28
  attr_reader :foobara_parent
@@ -35,4 +39,15 @@ class Thread
35
39
  def foobara_var_set(...)
36
40
  thread_variable_set(...)
37
41
  end
42
+
43
+ def foobara_with_var(key, value, &block)
44
+ old_value = foobara_var_get(key)
45
+
46
+ begin
47
+ foobara_var_set(key, value)
48
+ block.call
49
+ ensure
50
+ foobara_var_set(key, old_value)
51
+ end
52
+ end
38
53
  end
@@ -45,7 +45,7 @@ module Foobara
45
45
  category << processor
46
46
  end
47
47
 
48
- Types::Type.new(
48
+ type_class.new(
49
49
  strict_type_declaration,
50
50
  base_type:,
51
51
  # description: strict_type_declaration.is_a?(::Hash) && strict_type_declaration[:description],
@@ -60,6 +60,10 @@ module Foobara
60
60
  )
61
61
  end
62
62
 
63
+ def type_class
64
+ Types::Type
65
+ end
66
+
63
67
  # TODO: test that registering a custom type sets its name
64
68
  def type_name(strict_type_declaration)
65
69
  "Anonymous #{strict_type_declaration[:type]} extension"
@@ -15,7 +15,7 @@ module Foobara
15
15
 
16
16
  return if !start && registered?
17
17
 
18
- to_process = [*base_type, *element_type, *possible_errors.map(&:error_class)]
18
+ to_process = types_to_add_to_manifest
19
19
 
20
20
  if element_types
21
21
  to_process += case element_types
@@ -43,6 +43,10 @@ module Foobara
43
43
  result
44
44
  end
45
45
 
46
+ def types_to_add_to_manifest
47
+ [*base_type, *element_type, *possible_errors.map(&:error_class)]
48
+ end
49
+
46
50
  def deep_types_depended_on
47
51
  result = Set.new
48
52
  to_process = types_depended_on
@@ -323,7 +323,7 @@ module Foobara
323
323
  declaration_data:,
324
324
  types_depended_on: types.sort,
325
325
  possible_errors: possible_errors_manifests
326
- ).merge(description:, base_type: base_type&.full_type_name&.to_sym)
326
+ ).merge(description:, base_type: base_type_for_manifest)
327
327
 
328
328
  h.merge!(
329
329
  supported_processor_manifest(to_include).merge(
@@ -340,6 +340,10 @@ module Foobara
340
340
  super.merge(h)
341
341
  end
342
342
 
343
+ def base_type_for_manifest
344
+ base_type&.full_type_name&.to_sym
345
+ end
346
+
343
347
  def supported_processor_manifest(to_include)
344
348
  supported_casters = []
345
349
  supported_transformers = []
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.52
4
+ version: 0.0.53
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-30 00:00:00.000000000 Z
10
+ date: 2025-01-31 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bigdecimal
@@ -194,6 +194,7 @@ files:
194
194
  - projects/detached_entity/src/concerns/serialize.rb
195
195
  - projects/detached_entity/src/concerns/types.rb
196
196
  - projects/detached_entity/src/detached_entity.rb
197
+ - projects/detached_entity/src/detached_entity_type.rb
197
198
  - projects/detached_entity/src/extensions/builtin_types/detached_entity.rb
198
199
  - projects/detached_entity/src/extensions/builtin_types/detached_entity/casters/hash.rb
199
200
  - projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/attributes_declaration.rb