foobara 0.0.51 → 0.0.53
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/projects/detached_entity/src/concerns/aliases.rb +39 -0
- data/projects/detached_entity/src/concerns/associations.rb +4 -2
- data/projects/detached_entity/src/concerns/primary_key.rb +2 -2
- data/projects/detached_entity/src/concerns/reflection.rb +17 -28
- data/projects/detached_entity/src/concerns/serialize.rb +23 -0
- data/projects/detached_entity/src/detached_entity.rb +2 -0
- data/projects/detached_entity/src/detached_entity_type.rb +63 -0
- data/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/to_type_transformer.rb +4 -0
- data/projects/entity/lib/foobara/entity.rb +3 -0
- data/projects/manifest/src/foobara/manifest/type.rb +1 -0
- data/projects/model/src/concerns/aliases.rb +15 -0
- data/projects/model/src/concerns/reflection.rb +6 -6
- data/projects/model/src/concerns/types.rb +4 -0
- data/projects/model/src/model.rb +3 -2
- data/projects/thread_parent/src/thread_parent.rb +15 -0
- data/projects/type_declarations/src/handlers/extend_registered_type_declaration/to_type_transformer.rb +5 -1
- data/projects/types/src/type/concerns/reflection.rb +5 -1
- data/projects/types/src/type.rb +5 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f36fa530b7c550b95ee9f580590ad68e18700e80048746fb734078ea0e9744e
|
4
|
+
data.tar.gz: 1454b5d06e3be5c3be8b9cfee10b6e598b71ad74f409c7f09d2a66427f71f3a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a238d0b3ba1366f67a0edee344a7f0228367b56a0c45eabe230603310a4b36b9f13b765382907a9e8c72533f0ec18af6f1b956e575a0c79bffe08e036de3097
|
7
|
+
data.tar.gz: 99b3b4c279bc4104fc1faefda279bf4fadcae8ee57975655dec120f17ce5980fda6b2dccf1476e00df20460e3a091dba56f5c00afdc4907bdf62c374feddee78
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## [0.0.53] - 2025-01-30
|
2
|
+
|
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
|
5
|
+
|
1
6
|
## [0.0.51] - 2025-01-26
|
2
7
|
|
3
8
|
- Add a Type#remove_processor_by_symbol method to help with certain situations when defining custom types
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Foobara
|
2
|
+
class DetachedEntity < Model
|
3
|
+
module Concerns
|
4
|
+
module Aliases
|
5
|
+
include Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def depends_on(...)
|
9
|
+
foobara_depends_on(...)
|
10
|
+
end
|
11
|
+
|
12
|
+
def deep_depends_on(...)
|
13
|
+
foobara_deep_depends_on(...)
|
14
|
+
end
|
15
|
+
|
16
|
+
def associations(...)
|
17
|
+
foobara_associations(...)
|
18
|
+
end
|
19
|
+
|
20
|
+
def deep_associations(...)
|
21
|
+
foobara_deep_associations(...)
|
22
|
+
end
|
23
|
+
|
24
|
+
def attributes_type(...)
|
25
|
+
foobara_attributes_type(...)
|
26
|
+
end
|
27
|
+
|
28
|
+
def primary_key_attribute(...)
|
29
|
+
foobara_primary_key_attribute(...)
|
30
|
+
end
|
31
|
+
|
32
|
+
def model_name(...)
|
33
|
+
foobara_model_name(...)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -11,8 +11,8 @@ module Foobara
|
|
11
11
|
|
12
12
|
alias associations foobara_associations
|
13
13
|
|
14
|
-
def
|
15
|
-
@
|
14
|
+
def foobara_deep_associations
|
15
|
+
@foobara_deep_associations ||= begin
|
16
16
|
deep = {}
|
17
17
|
|
18
18
|
associations.each_pair do |data_path, type|
|
@@ -29,6 +29,8 @@ module Foobara
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
alias deep_associations foobara_deep_associations
|
33
|
+
|
32
34
|
# TODO: stamp this metadata out somewhere, preferably on deep_associations hash somehow
|
33
35
|
def association(name, *association_identifiers)
|
34
36
|
target_association_key = association_for(association_identifiers)
|
@@ -28,8 +28,8 @@ module Foobara
|
|
28
28
|
def foobara_primary_key_attribute
|
29
29
|
return @foobara_primary_key_attribute if @foobara_primary_key_attribute
|
30
30
|
|
31
|
-
|
32
|
-
@foobara_primary_key_attribute = superclass.
|
31
|
+
if superclass != DetachedEntity && superclass.respond_to?(:foobara_primary_key_attribute)
|
32
|
+
@foobara_primary_key_attribute = superclass.foobara_primary_key_attribute
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -2,29 +2,15 @@ module Foobara
|
|
2
2
|
class DetachedEntity < Model
|
3
3
|
module Concerns
|
4
4
|
module Reflection
|
5
|
-
class CannotConvertRecordWithoutPrimaryKeyToJsonError < StandardError; end
|
6
|
-
|
7
5
|
include Concern
|
8
6
|
|
9
|
-
def inspect
|
10
|
-
"<#{entity_name}:#{primary_key}>"
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_json(*_args)
|
14
|
-
primary_key&.to_json || raise(
|
15
|
-
CannotConvertRecordWithoutPrimaryKeyToJsonError,
|
16
|
-
"Cannot call record.to_json on unless record has a primary key. " \
|
17
|
-
"Consider instead calling record.attributes.to_json instead."
|
18
|
-
)
|
19
|
-
end
|
20
|
-
|
21
7
|
module ClassMethods
|
22
|
-
def
|
23
|
-
|
8
|
+
def foobara_depends_on
|
9
|
+
foobara_associations.values.map(&:target_class).uniq
|
24
10
|
end
|
25
11
|
|
26
|
-
def
|
27
|
-
types =
|
12
|
+
def foobara_deep_depends_on
|
13
|
+
types = foobara_deep_associations.sort_by do |path, _type|
|
28
14
|
[DataPath.new(path).path.size, path]
|
29
15
|
end.map(&:last)
|
30
16
|
|
@@ -32,29 +18,32 @@ module Foobara
|
|
32
18
|
end
|
33
19
|
|
34
20
|
def foobara_manifest(to_include: Set.new)
|
35
|
-
associations =
|
21
|
+
associations = foobara_associations.map do |(path, type)|
|
36
22
|
entity_class = type.target_class
|
37
|
-
entity_name = entity_class.
|
23
|
+
entity_name = entity_class.foobara_type.scoped_full_name
|
38
24
|
|
39
25
|
[path, entity_name]
|
40
26
|
end.sort.to_h
|
41
27
|
|
42
|
-
deep_associations =
|
28
|
+
deep_associations = foobara_deep_associations.map do |(path, type)|
|
43
29
|
entity_class = type.target_class
|
44
|
-
entity_name = entity_class.
|
30
|
+
entity_name = entity_class.foobara_type.scoped_full_name
|
45
31
|
|
46
32
|
[path, entity_name]
|
47
33
|
end.sort.to_h
|
48
34
|
|
49
|
-
|
35
|
+
base_manifest = superclass.respond_to?(:foobara_manifest) ? super : {}
|
36
|
+
|
37
|
+
base_manifest.merge(
|
50
38
|
Util.remove_blank(
|
51
|
-
depends_on:
|
52
|
-
deep_depends_on:
|
39
|
+
depends_on: foobara_depends_on.map(&:full_entity_name),
|
40
|
+
deep_depends_on: foobara_deep_depends_on.map(&:full_entity_name),
|
53
41
|
associations:,
|
54
42
|
deep_associations:,
|
55
|
-
entity_name
|
56
|
-
primary_key_attribute
|
57
|
-
primary_key_type:
|
43
|
+
entity_name: foobara_model_name,
|
44
|
+
primary_key_attribute: foobara_primary_key_attribute,
|
45
|
+
primary_key_type:
|
46
|
+
foobara_attributes_type.declaration_data[:element_type_declarations][foobara_primary_key_attribute]
|
58
47
|
)
|
59
48
|
)
|
60
49
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Foobara
|
2
|
+
class DetachedEntity < Model
|
3
|
+
module Concerns
|
4
|
+
module Serialize
|
5
|
+
class CannotConvertRecordWithoutPrimaryKeyToJsonError < StandardError; end
|
6
|
+
|
7
|
+
include Concern
|
8
|
+
|
9
|
+
def inspect
|
10
|
+
"<#{entity_name}:#{primary_key}>"
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_json(*_args)
|
14
|
+
primary_key&.to_json || raise(
|
15
|
+
CannotConvertRecordWithoutPrimaryKeyToJsonError,
|
16
|
+
"Cannot call record.to_json on unless record has a primary key. " \
|
17
|
+
"Consider instead calling record.attributes.to_json instead."
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -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
|
@@ -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
|
@@ -7,12 +7,12 @@ module Foobara
|
|
7
7
|
module ClassMethods
|
8
8
|
def foobara_manifest(to_include: Set.new)
|
9
9
|
Util.remove_blank(
|
10
|
-
attributes_type:
|
11
|
-
organization_name
|
12
|
-
domain_name
|
13
|
-
model_name
|
14
|
-
model_base_class:
|
15
|
-
model_class:
|
10
|
+
attributes_type: foobara_attributes_type.declaration_data,
|
11
|
+
organization_name: foobara_type.foobara_domain.foobara_organization_name,
|
12
|
+
domain_name: foobara_type.foobara_domain.foobara_domain_name,
|
13
|
+
model_name: foobara_model_name,
|
14
|
+
model_base_class: foobara_type.declaration_data[:model_base_class],
|
15
|
+
model_class: foobara_type.declaration_data[:model_class]
|
16
16
|
)
|
17
17
|
end
|
18
18
|
end
|
data/projects/model/src/model.rb
CHANGED
@@ -8,6 +8,7 @@ module Foobara
|
|
8
8
|
|
9
9
|
include Concerns::Types
|
10
10
|
include Concerns::Reflection
|
11
|
+
include Concerns::Aliases
|
11
12
|
|
12
13
|
class << self
|
13
14
|
attr_accessor :is_abstract
|
@@ -84,8 +85,8 @@ module Foobara
|
|
84
85
|
end
|
85
86
|
end
|
86
87
|
|
87
|
-
def
|
88
|
-
|
88
|
+
def foobara_model_name
|
89
|
+
foobara_type&.scoped_name || Util.non_full_name(self)
|
89
90
|
rescue Foobara::Scoped::NoScopedPathSetError
|
90
91
|
# :nocov:
|
91
92
|
Util.non_full_name(self)
|
@@ -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
|
-
|
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 =
|
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
|
data/projects/types/src/type.rb
CHANGED
@@ -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:
|
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.
|
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-
|
10
|
+
date: 2025-01-31 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bigdecimal
|
@@ -186,12 +186,15 @@ files:
|
|
186
186
|
- projects/delegate/lib/foobara/delegate.rb
|
187
187
|
- projects/delegate/src/extensions/module.rb
|
188
188
|
- projects/detached_entity/lib/foobara/detached_entity.rb
|
189
|
+
- projects/detached_entity/src/concerns/aliases.rb
|
189
190
|
- projects/detached_entity/src/concerns/associations.rb
|
190
191
|
- projects/detached_entity/src/concerns/equality.rb
|
191
192
|
- projects/detached_entity/src/concerns/primary_key.rb
|
192
193
|
- projects/detached_entity/src/concerns/reflection.rb
|
194
|
+
- projects/detached_entity/src/concerns/serialize.rb
|
193
195
|
- projects/detached_entity/src/concerns/types.rb
|
194
196
|
- projects/detached_entity/src/detached_entity.rb
|
197
|
+
- projects/detached_entity/src/detached_entity_type.rb
|
195
198
|
- projects/detached_entity/src/extensions/builtin_types/detached_entity.rb
|
196
199
|
- projects/detached_entity/src/extensions/builtin_types/detached_entity/casters/hash.rb
|
197
200
|
- projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/attributes_declaration.rb
|
@@ -270,6 +273,7 @@ files:
|
|
270
273
|
- projects/manifest/src/foobara/manifest/type.rb
|
271
274
|
- projects/manifest/src/foobara/manifest/type_declaration.rb
|
272
275
|
- projects/model/lib/foobara/model.rb
|
276
|
+
- projects/model/src/concerns/aliases.rb
|
273
277
|
- projects/model/src/concerns/reflection.rb
|
274
278
|
- projects/model/src/concerns/types.rb
|
275
279
|
- projects/model/src/extensions/builtin_types/model/casters/hash.rb
|
@@ -438,7 +442,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
438
442
|
- !ruby/object:Gem::Version
|
439
443
|
version: '0'
|
440
444
|
requirements: []
|
441
|
-
rubygems_version: 3.6.
|
445
|
+
rubygems_version: 3.6.3
|
442
446
|
specification_version: 4
|
443
447
|
summary: A command-centric and discoverable software framework with a focus on domain
|
444
448
|
concepts and abstracting away integration code
|