foobara 0.0.80 → 0.0.81
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 +4 -0
- data/projects/detached_entity/src/detached_entity.rb +0 -6
- data/projects/detached_entity/src/extensions/builtin_types/detached_entity/casters/hash.rb +4 -20
- data/projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/attributes_declaration.rb +7 -1
- data/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/model_class_desugarizer.rb +0 -4
- data/projects/domain/src/domain_module_extension.rb +32 -6
- data/projects/model/src/concerns/classes.rb +75 -0
- data/projects/model/src/concerns/types.rb +17 -7
- data/projects/model/src/extensions/builtin_types/model/casters/hash.rb +20 -4
- data/projects/model/src/extensions/builtin_types/model/validators/attributes_declaration.rb +7 -1
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/model_class_desugarizer.rb +65 -87
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb +16 -3
- data/projects/model/src/model.rb +40 -42
- data/projects/value/src/processor/casting.rb +14 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66f1d5b1015809a2646a0627b8d6af04bdca39257a21a361e5cb78807b0ba611
|
4
|
+
data.tar.gz: 565397a74e404cdba4e629d2bb28b27dcb5b23f2e144a8dfeccac22690600a45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42b0474e8712dfc36495379cd12d61b7c6aee754382cce807a330038d5fd249ebfe3bc4f7b503d0a1d80b92c12b67ab1297007d3535e9983e9ae1a116e8bd31b
|
7
|
+
data.tar.gz: a12f6239df09e306ee8a1587f56e74cce4d9bfc78393daeb648b82c91f0d07806ba8e5ebec48b80f4f77e4e956e82667d7b95b0448367a7b5c1ae4d862380a3a
|
data/CHANGELOG.md
CHANGED
@@ -2,35 +2,19 @@ module Foobara
|
|
2
2
|
module BuiltinTypes
|
3
3
|
module DetachedEntity
|
4
4
|
module Casters
|
5
|
-
class Hash <
|
5
|
+
class Hash < BuiltinTypes::Model::Casters::Hash
|
6
6
|
class << self
|
7
7
|
def requires_parent_declaration_data?
|
8
8
|
true
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
entity_class.send(build_method(symbolized_attributes), symbolized_attributes)
|
16
|
-
end
|
17
|
-
|
18
|
-
def build_method(_symbolized_attributes)
|
19
|
-
:new
|
12
|
+
def expected_type_symbol
|
13
|
+
:detached_entity
|
20
14
|
end
|
21
15
|
|
22
16
|
def entity_class
|
23
|
-
|
24
|
-
|
25
|
-
if type == expected_type_symbol
|
26
|
-
Object.const_get(parent_declaration_data[:model_class])
|
27
|
-
else
|
28
|
-
Foobara::Namespace.current.foobara_lookup_type!(type).target_class
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def expected_type_symbol
|
33
|
-
:detached_entity
|
17
|
+
model_class
|
34
18
|
end
|
35
19
|
end
|
36
20
|
end
|
@@ -15,7 +15,13 @@ module Foobara
|
|
15
15
|
|
16
16
|
def entity_class
|
17
17
|
if parent_declaration_data.key?(:model_class)
|
18
|
-
|
18
|
+
model_class_name = parent_declaration_data[:model_class]
|
19
|
+
|
20
|
+
if Object.const_defined?(model_class_name)
|
21
|
+
Object.const_get(parent_declaration_data[:model_class])
|
22
|
+
else
|
23
|
+
Namespace.current.foobara_lookup_type!(model_class_name).target_class
|
24
|
+
end
|
19
25
|
elsif parent_declaration_data[:type] != expected_type_symbol
|
20
26
|
model_type = type_for_declaration(parent_declaration_data[:type])
|
21
27
|
model_type.target_class
|
@@ -281,7 +281,14 @@ module Foobara
|
|
281
281
|
def foobara_register_model(model_class)
|
282
282
|
type = model_class.model_type
|
283
283
|
|
284
|
-
|
284
|
+
full_name = type.scoped_full_name
|
285
|
+
|
286
|
+
if model_class.full_model_name.size > full_name.size
|
287
|
+
# TODO: why does this happen exactly??
|
288
|
+
full_name = model_class.full_model_name
|
289
|
+
end
|
290
|
+
|
291
|
+
if type.scoped_path_set? && foobara_registered?(full_name, mode: Namespace::LookupMode::DIRECT)
|
285
292
|
# :nocov:
|
286
293
|
raise AlreadyRegisteredError, "Already registered: #{type.inspect}"
|
287
294
|
# :nocov:
|
@@ -293,6 +300,11 @@ module Foobara
|
|
293
300
|
type.target_class
|
294
301
|
end
|
295
302
|
|
303
|
+
def foobara_register_and_deanonymize_entity(name, *, &)
|
304
|
+
entity_class = foobara_register_entity(name, *, &)
|
305
|
+
Foobara::Model.deanonymize_class(entity_class)
|
306
|
+
end
|
307
|
+
|
296
308
|
# TODO: kill this off
|
297
309
|
def foobara_register_entity(name, *args, &block)
|
298
310
|
# TODO: introduce a Namespace#scope method to simplify this a bit
|
@@ -336,27 +348,41 @@ module Foobara
|
|
336
348
|
# TODO: reuse the model_base_class primary key if it has one...
|
337
349
|
primary_key = attributes_type.element_types.keys.first
|
338
350
|
|
339
|
-
foobara_type_builder.type_for_declaration(
|
351
|
+
entity_type = foobara_type_builder.type_for_declaration(
|
340
352
|
Util.remove_blank(
|
341
353
|
type: :entity,
|
342
354
|
name:,
|
343
355
|
model_base_class:,
|
344
|
-
attributes_declaration: attributes_type_declaration,
|
345
356
|
model_module: self,
|
357
|
+
attributes_declaration: attributes_type_declaration,
|
346
358
|
primary_key:,
|
347
359
|
description:,
|
348
360
|
_desugarized: { type_absolutified: true }
|
349
361
|
)
|
350
|
-
)
|
362
|
+
)
|
363
|
+
|
364
|
+
entity_type.target_class
|
351
365
|
end
|
352
366
|
end
|
353
367
|
|
368
|
+
def foobara_register_and_deanonymize_entities(entity_names_to_attributes)
|
369
|
+
entities = []
|
370
|
+
|
371
|
+
entity_names_to_attributes.each_pair do |entity_name, attributes_declaration|
|
372
|
+
entities << foobara_register_and_deanonymize_entity(entity_name, attributes_declaration)
|
373
|
+
end
|
374
|
+
|
375
|
+
entities
|
376
|
+
end
|
377
|
+
|
354
378
|
def foobara_register_entities(entity_names_to_attributes)
|
379
|
+
entities = []
|
380
|
+
|
355
381
|
entity_names_to_attributes.each_pair do |entity_name, attributes_type_declaration|
|
356
|
-
foobara_register_entity(entity_name, attributes_type_declaration)
|
382
|
+
entities << foobara_register_entity(entity_name, attributes_type_declaration)
|
357
383
|
end
|
358
384
|
|
359
|
-
|
385
|
+
entities
|
360
386
|
end
|
361
387
|
|
362
388
|
def foobara_can_call_subcommands_from?(other_domain)
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Model
|
3
|
+
module Concerns
|
4
|
+
module Classes
|
5
|
+
include Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def deanonymize_class(anonymous_model_class)
|
9
|
+
type_declaration = anonymous_model_class.model_type.declaration_data
|
10
|
+
model_module_name = type_declaration[:model_module]
|
11
|
+
|
12
|
+
model_module = if model_module_name
|
13
|
+
if Object.const_defined?(model_module_name)
|
14
|
+
Object.const_get(model_module_name)
|
15
|
+
else
|
16
|
+
Util.make_module_p(model_module_name)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if model_module == GlobalDomain || !model_module
|
21
|
+
model_module = Object
|
22
|
+
end
|
23
|
+
|
24
|
+
klass = type_declaration[:model_class]
|
25
|
+
|
26
|
+
if klass && Object.const_defined?(klass) && Object.const_get(klass).is_a?(::Class)
|
27
|
+
# should we raise an exception??
|
28
|
+
Object.const_get(klass)
|
29
|
+
else
|
30
|
+
model_name = type_declaration[:name]
|
31
|
+
|
32
|
+
existing_class = if model_module.const_defined?(model_name)
|
33
|
+
model_module.const_get(model_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
# TODO: This is a pretty crazy situation and hacky. Should come up with a better solution.
|
37
|
+
# Here's the situation: if models are nested, like A::B and A and A::B are modules, then
|
38
|
+
# if A::B is imported first, A will be created as a module via make_module_p.
|
39
|
+
# But then when we are here creating A, A is already in use incorrectly as a module.
|
40
|
+
# We need to move A out of the way but set all of its constants on the newly created model A.
|
41
|
+
if existing_class.is_a?(::Module) && !existing_class.is_a?(::Class)
|
42
|
+
if existing_class.instance_variable_get(:@foobara_created_via_make_class)
|
43
|
+
existing_module_to_copy_over = existing_class
|
44
|
+
parent_mod = Util.module_for(existing_class)
|
45
|
+
parent_mod.send(:remove_const, Util.non_full_name(existing_class))
|
46
|
+
else
|
47
|
+
# :nocov:
|
48
|
+
return existing_class
|
49
|
+
# :nocov:
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
if existing_module_to_copy_over
|
54
|
+
Foobara::Domain::DomainModuleExtension._copy_constants(
|
55
|
+
existing_module_to_copy_over, anonymous_model_class
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
if model_name.include?("::")
|
60
|
+
model_module_name = "#{model_module.name}::#{model_name.split("::")[..-2].join("::")}"
|
61
|
+
model_module = Util.make_module_p(model_module_name, tag: true)
|
62
|
+
end
|
63
|
+
|
64
|
+
const_name = model_name.split("::").last
|
65
|
+
|
66
|
+
model_module.const_set(const_name, anonymous_model_class)
|
67
|
+
|
68
|
+
anonymous_model_class
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -85,20 +85,30 @@ module Foobara
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def type_declaration(attributes_declaration)
|
88
|
-
if name
|
89
|
-
|
90
|
-
|
88
|
+
if name
|
89
|
+
model_base_class = superclass.name
|
90
|
+
model_class = name
|
91
|
+
|
92
|
+
if name.start_with?(closest_namespace_module.name)
|
93
|
+
model_module_name = closest_namespace_module.name
|
94
|
+
model_name = name.gsub(/^#{closest_namespace_module.name}::/, "")
|
95
|
+
else
|
96
|
+
model_module_name = nil
|
97
|
+
model_name = name
|
98
|
+
end
|
91
99
|
else
|
92
|
-
model_module_name =
|
93
|
-
|
100
|
+
model_module_name = model_type.declaration_data[:model_module]
|
101
|
+
model_class = model_type.declaration_data[:model_class]
|
102
|
+
model_name = model_type.scoped_name
|
103
|
+
model_base_class = superclass.name || superclass.model_type.scoped_full_name
|
94
104
|
end
|
95
105
|
|
96
106
|
Util.remove_blank(
|
97
107
|
type: :model,
|
98
108
|
name: model_name,
|
99
109
|
model_module: model_module_name,
|
100
|
-
model_class
|
101
|
-
model_base_class
|
110
|
+
model_class:,
|
111
|
+
model_base_class:,
|
102
112
|
attributes_declaration:,
|
103
113
|
description:,
|
104
114
|
_desugarized: { type_absolutified: true },
|
@@ -10,18 +10,34 @@ module Foobara
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def cast(attributes)
|
13
|
-
|
13
|
+
symbolized_attributes = super
|
14
|
+
|
15
|
+
model_class.send(build_method(symbolized_attributes), symbolized_attributes)
|
14
16
|
end
|
15
17
|
|
16
18
|
def model_class
|
17
19
|
type = parent_declaration_data[:type]
|
18
20
|
|
19
|
-
if type ==
|
20
|
-
|
21
|
+
if type == expected_type_symbol
|
22
|
+
model_class_name = parent_declaration_data[:model_class]
|
23
|
+
|
24
|
+
if Object.const_defined?(model_class_name)
|
25
|
+
Object.const_get(parent_declaration_data[:model_class])
|
26
|
+
else
|
27
|
+
Namespace.current.foobara_lookup_type!(model_class_name).target_class
|
28
|
+
end
|
21
29
|
else
|
22
|
-
|
30
|
+
Namespace.current.foobara_lookup_type!(type).target_class
|
23
31
|
end
|
24
32
|
end
|
33
|
+
|
34
|
+
def expected_type_symbol
|
35
|
+
:model
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_method(_symbolized_attributes)
|
39
|
+
:new
|
40
|
+
end
|
25
41
|
end
|
26
42
|
end
|
27
43
|
end
|
@@ -25,7 +25,13 @@ module Foobara
|
|
25
25
|
model_class_name = parent_declaration_data[:model_class]
|
26
26
|
|
27
27
|
if model_class_name
|
28
|
-
Object.
|
28
|
+
model_class = if Object.const_defined?(model_class_name)
|
29
|
+
Object.const_get(model_class_name)
|
30
|
+
else
|
31
|
+
Namespace.current.foobara_lookup_type!(model_class_name).target_class
|
32
|
+
end
|
33
|
+
|
34
|
+
model_class.possible_errors
|
29
35
|
else
|
30
36
|
super
|
31
37
|
end
|
@@ -15,100 +15,78 @@ module Foobara
|
|
15
15
|
Foobara::Model
|
16
16
|
end
|
17
17
|
|
18
|
+
# TODO: considerg splitting this up into multiple desugarizers
|
18
19
|
def desugarize(strictish_type_declaration)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
20
|
+
if strictish_type_declaration.key?(:model_module)
|
21
|
+
model_module = strictish_type_declaration[:model_module]
|
22
|
+
|
23
|
+
strictish_type_declaration[:model_module] =
|
24
|
+
case model_module
|
25
|
+
when ::Module
|
26
|
+
model_module.name
|
27
|
+
when ::String, nil
|
28
|
+
model_module
|
29
|
+
else
|
30
|
+
# :nocov:
|
31
|
+
raise ArgumentError, "expected #{model_module} to be a module or module name"
|
32
|
+
# :nocov:
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
if strictish_type_declaration.key?(:model_class)
|
37
|
+
klass = strictish_type_declaration[:model_class]
|
38
|
+
|
39
|
+
model_class_name = if klass && Object.const_defined?(klass) && Object.const_get(klass).is_a?(::Class)
|
40
|
+
model_class = Object.const_get(klass)
|
41
|
+
|
42
|
+
unless strictish_type_declaration[:model_module]
|
43
|
+
model_module = Util.module_for(model_class)
|
44
|
+
|
45
|
+
unless model_module == Object
|
46
|
+
strictish_type_declaration[:model_module] = model_module&.name
|
47
|
+
end
|
36
48
|
end
|
37
49
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
existing_module_to_copy_over = existing_class
|
75
|
-
parent_mod = Util.module_for(existing_class)
|
76
|
-
parent_mod.send(:remove_const, Util.non_full_name(existing_class))
|
77
|
-
existing_class = nil
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# TODO: feels too destructive to be in a desugarizer. Technically probably should be in the
|
82
|
-
# to type transformer instead.
|
83
|
-
existing_class || model_base_class.subclass(
|
84
|
-
**create_model_class_args(model_module:, type_declaration: strictish_type_declaration)
|
85
|
-
).tap do |model_class|
|
86
|
-
if existing_module_to_copy_over
|
87
|
-
Foobara::Domain::DomainModuleExtension._copy_constants(
|
88
|
-
existing_module_to_copy_over, model_class
|
89
|
-
)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
strictish_type_declaration[:model_class] = model_class.name
|
95
|
-
model_module ||= Util.module_for(model_class)
|
96
|
-
|
97
|
-
model_module = nil if model_module == Object
|
98
|
-
|
99
|
-
strictish_type_declaration[:model_module] = model_module&.name
|
100
|
-
strictish_type_declaration[:model_base_class] = model_class.superclass.name
|
50
|
+
strictish_type_declaration[:model_base_class] = model_class.superclass.name
|
51
|
+
|
52
|
+
model_class.name
|
53
|
+
elsif klass.is_a?(::String)
|
54
|
+
klass
|
55
|
+
else
|
56
|
+
# :nocov:
|
57
|
+
raise ArgumentError, "expected #{klass} to be a class or class name"
|
58
|
+
# :nocov:
|
59
|
+
end
|
60
|
+
|
61
|
+
strictish_type_declaration[:model_class] = model_class_name
|
62
|
+
end
|
63
|
+
|
64
|
+
model_base_class = strictish_type_declaration[:model_base_class] || default_model_base_class
|
65
|
+
|
66
|
+
strictish_type_declaration[:model_base_class] =
|
67
|
+
case model_base_class
|
68
|
+
when ::Class
|
69
|
+
model_base_class.name || model_base_class.model_name
|
70
|
+
when ::String
|
71
|
+
model_base_class
|
72
|
+
else
|
73
|
+
# :nocov:
|
74
|
+
raise ArgumentError, "expected #{model_base_class} to be a class or class name"
|
75
|
+
# :nocov:
|
76
|
+
end
|
77
|
+
|
78
|
+
if strictish_type_declaration[:name].is_a?(::Symbol)
|
79
|
+
strictish_type_declaration[:name] = strictish_type_declaration[:name].to_s
|
80
|
+
end
|
81
|
+
|
82
|
+
strictish_type_declaration[:model_class] ||= [
|
83
|
+
*strictish_type_declaration[:model_module],
|
84
|
+
strictish_type_declaration[:name]
|
85
|
+
].join("::")
|
101
86
|
|
102
87
|
strictish_type_declaration
|
103
88
|
end
|
104
89
|
|
105
|
-
def create_model_class_args(model_module:, type_declaration:)
|
106
|
-
{
|
107
|
-
name: type_declaration[:name],
|
108
|
-
model_module:
|
109
|
-
}
|
110
|
-
end
|
111
|
-
|
112
90
|
def priority
|
113
91
|
Priority::LOW
|
114
92
|
end
|
@@ -5,7 +5,21 @@ module Foobara
|
|
5
5
|
class ToTypeTransformer < ExtendRegisteredTypeDeclaration::ToTypeTransformer
|
6
6
|
# TODO: make declaration validator for model_class and model_base_class
|
7
7
|
def target_classes(strict_type_declaration)
|
8
|
-
|
8
|
+
model_class_name = strict_type_declaration[:model_class]
|
9
|
+
|
10
|
+
if Object.const_defined?(model_class_name) && Object.const_get(model_class_name).is_a?(::Class)
|
11
|
+
Object.const_get(model_class_name)
|
12
|
+
else
|
13
|
+
base_class_name = strict_type_declaration[:model_base_class]
|
14
|
+
|
15
|
+
base_class = if Object.const_defined?(base_class_name)
|
16
|
+
Object.const_get(base_class_name)
|
17
|
+
else
|
18
|
+
foobara_domain.foobara_lookup_type!(base_class_name).target_class
|
19
|
+
end
|
20
|
+
|
21
|
+
base_class.subclass(name: model_class_name)
|
22
|
+
end
|
9
23
|
end
|
10
24
|
|
11
25
|
# TODO: must explode if name missing...
|
@@ -32,14 +46,13 @@ module Foobara
|
|
32
46
|
model_class = type.target_class
|
33
47
|
existing_model_type = model_class.model_type
|
34
48
|
|
35
|
-
domain = model_class.domain || Domain.global
|
36
|
-
|
37
49
|
if existing_model_type
|
38
50
|
# :nocov:
|
39
51
|
raise "Did not expect #{type.declaration_data[:name]} to already exist"
|
40
52
|
# :nocov:
|
41
53
|
else
|
42
54
|
model_class.model_type = type
|
55
|
+
domain = model_class.domain
|
43
56
|
type.type_symbol = type.declaration_data[:name]
|
44
57
|
model_class.description type.declaration_data[:description]
|
45
58
|
domain.foobara_register_model(model_class)
|
data/projects/model/src/model.rb
CHANGED
@@ -9,6 +9,7 @@ module Foobara
|
|
9
9
|
include Concerns::Types
|
10
10
|
include Concerns::Reflection
|
11
11
|
include Concerns::Aliases
|
12
|
+
include Concerns::Classes
|
12
13
|
|
13
14
|
class << self
|
14
15
|
attr_accessor :is_abstract
|
@@ -65,7 +66,29 @@ module Foobara
|
|
65
66
|
|
66
67
|
def domain
|
67
68
|
if model_type
|
68
|
-
model_type.foobara_domain
|
69
|
+
domain = model_type.foobara_domain
|
70
|
+
|
71
|
+
if domain == GlobalDomain
|
72
|
+
module_name = model_type.declaration_data[:model_module]
|
73
|
+
|
74
|
+
begin
|
75
|
+
Domain.to_domain(module_name)
|
76
|
+
rescue Domain::NoSuchDomain
|
77
|
+
module_to_check = module_name
|
78
|
+
|
79
|
+
loop do
|
80
|
+
domain = if Object.const_defined?(module_to_check)
|
81
|
+
return Domain.domain_through_modules(Object.const_get(module_to_check))
|
82
|
+
elsif module_to_check.include?("::")
|
83
|
+
module_to_check = module_to_check.split("::")[..-2].join("::")
|
84
|
+
else
|
85
|
+
return GlobalDomain
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
else
|
90
|
+
domain
|
91
|
+
end
|
69
92
|
else
|
70
93
|
Domain.domain_through_modules(self)
|
71
94
|
end
|
@@ -86,15 +109,19 @@ module Foobara
|
|
86
109
|
end
|
87
110
|
|
88
111
|
def foobara_model_name
|
89
|
-
foobara_type&.
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
112
|
+
if foobara_type&.scoped_path_set?
|
113
|
+
foobara_type.scoped_name
|
114
|
+
else
|
115
|
+
Util.non_full_name(self) || model_name&.split("::")&.last
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def foobara_name
|
120
|
+
foobara_model_name
|
94
121
|
end
|
95
122
|
|
96
123
|
def full_model_name
|
97
|
-
model_type&.scoped_full_name
|
124
|
+
[*model_type&.scoped_full_name, model_name].max_by(&:size)
|
98
125
|
end
|
99
126
|
|
100
127
|
def possible_errors(mutable: true)
|
@@ -123,46 +150,17 @@ module Foobara
|
|
123
150
|
end
|
124
151
|
end
|
125
152
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
def subclass(**opts)
|
131
|
-
invalid_opts = opts.keys - allowed_subclass_opts
|
132
|
-
|
133
|
-
unless invalid_opts.empty?
|
134
|
-
# :nocov:
|
135
|
-
raise ArgumentError, "Invalid opts #{invalid_opts} expected only #{allowed_subclass_opts}"
|
136
|
-
# :nocov:
|
137
|
-
end
|
138
|
-
|
139
|
-
model_name = opts[:name]
|
140
|
-
|
141
|
-
if model_name.is_a?(::Symbol)
|
142
|
-
model_name = model_name.to_s
|
143
|
-
end
|
153
|
+
# will create an anonymous subclass
|
154
|
+
# TODO: change to a normal parameter since it's just name
|
155
|
+
def subclass(name:)
|
156
|
+
name = name.to_s if name.is_a?(::Symbol)
|
144
157
|
|
145
158
|
# TODO: How are we going to set the domain and organization?
|
146
|
-
|
159
|
+
Class.new(self) do
|
147
160
|
singleton_class.define_method :model_name do
|
148
|
-
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
if opts.key?(:model_module)
|
153
|
-
model_module = opts[:model_module]
|
154
|
-
|
155
|
-
if model_name.include?("::")
|
156
|
-
model_module_name = "#{model_module.name}::#{model_name.split("::")[..-2].join("::")}"
|
157
|
-
model_module = Util.make_module_p(model_module_name, tag: true)
|
161
|
+
name
|
158
162
|
end
|
159
|
-
|
160
|
-
const_name = model_name.split("::").last
|
161
|
-
|
162
|
-
model_module.const_set(const_name, model_class)
|
163
163
|
end
|
164
|
-
|
165
|
-
model_class
|
166
164
|
end
|
167
165
|
end
|
168
166
|
|
@@ -61,7 +61,20 @@ module Foobara
|
|
61
61
|
def does_not_need_cast_processor
|
62
62
|
return @does_not_need_cast_processor if defined?(@does_not_need_cast_processor)
|
63
63
|
|
64
|
-
|
64
|
+
errorified_name = target_classes.map do |c|
|
65
|
+
if c.name
|
66
|
+
c.name
|
67
|
+
elsif c.respond_to?(:foobara_name)
|
68
|
+
c.foobara_name
|
69
|
+
else
|
70
|
+
# TODO: test this code path
|
71
|
+
# :nocov:
|
72
|
+
"Anon"
|
73
|
+
# :nocov:
|
74
|
+
end
|
75
|
+
end.map { |name| name.split("::").last }.sort.join("Or")
|
76
|
+
|
77
|
+
class_name = "NoCastNeededIfIsA#{errorified_name}"
|
65
78
|
|
66
79
|
@does_not_need_cast_processor = if target_classes && !target_classes.empty?
|
67
80
|
Caster.subclass(
|
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.81
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-21 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bigdecimal
|
@@ -295,6 +295,7 @@ files:
|
|
295
295
|
- projects/manifest/src/foobara/manifest/type_declaration.rb
|
296
296
|
- projects/model/lib/foobara/model.rb
|
297
297
|
- projects/model/src/concerns/aliases.rb
|
298
|
+
- projects/model/src/concerns/classes.rb
|
298
299
|
- projects/model/src/concerns/reflection.rb
|
299
300
|
- projects/model/src/concerns/types.rb
|
300
301
|
- projects/model/src/extensions/builtin_types/model/casters/hash.rb
|