foobara-remote-imports 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/src/foobara/remote_imports/import_type.rb +41 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74a7b47ff503e5d7bf90b2100497e1c07998efda26baf2f2ea0d7bdab3f978b8
|
4
|
+
data.tar.gz: 0c78bac42ce7fb38c9d5362d73827786148421e27c2ff0425e4c6a8875a0dbf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f2dc5b69968131bf1e5588c861e9a2cfa25bf6dd394b2a3e76090ed54ea86feef3ad8ee936ff4872d90a5fb83adcdd93b323ca9337fb64afc8f6ebf37d32579
|
7
|
+
data.tar.gz: e26f245c4dcf3b66d9b5683e89beef8a30c5df19688afb4de2653c569dd5be0ae6d330a59a1a28ef8a3c9973b9fd6a169ce88928a0ae777aba24f7df071a5925
|
data/CHANGELOG.md
CHANGED
@@ -15,6 +15,8 @@ module Foobara
|
|
15
15
|
mode: Namespace::LookupMode::ABSOLUTE
|
16
16
|
)
|
17
17
|
|
18
|
+
# TODO: might this be a sign of a name collision? Maybe better to give a meaningful error if the type isn't in
|
19
|
+
# #already_imported ??
|
18
20
|
return if existing_type
|
19
21
|
|
20
22
|
domain_manifest = manifest_to_import.domain
|
@@ -51,9 +53,47 @@ module Foobara
|
|
51
53
|
Util.make_module_p(containing_module_name, tag: true)
|
52
54
|
end
|
53
55
|
|
54
|
-
|
56
|
+
# Warning: cannot desugarize this because unfortunately desugarizing an entity declaration will actually
|
57
|
+
# create the entity class, which should be considered a bug.
|
58
|
+
declaration_data = manifest_to_import.declaration_data
|
59
|
+
|
60
|
+
if entity?(declaration_data)
|
61
|
+
declaration_data = entity_to_model(declaration_data)
|
62
|
+
end
|
63
|
+
|
64
|
+
type = domain.foobara_type_from_strict_stringified_declaration(declaration_data)
|
55
65
|
domain.foobara_register_type(manifest_to_import.scoped_path, type)
|
56
66
|
end
|
67
|
+
|
68
|
+
def entity?(declaration_data)
|
69
|
+
declaration_data["type"] == "entity"
|
70
|
+
end
|
71
|
+
|
72
|
+
# TODO: use a domain mapper??
|
73
|
+
def entity_to_model(declaration_data)
|
74
|
+
declaration_data = Util.deep_dup(declaration_data)
|
75
|
+
|
76
|
+
primary_key_attribute = declaration_data.delete("primary_key")
|
77
|
+
|
78
|
+
unless primary_key_attribute
|
79
|
+
# :nocov:
|
80
|
+
raise "Missing primary key attribute"
|
81
|
+
# :nocov:
|
82
|
+
end
|
83
|
+
|
84
|
+
unless declaration_data["model_base_class"] == "Foobara::Entity"
|
85
|
+
# :nocov:
|
86
|
+
raise "Expected model base class to be Foobara::Entity"
|
87
|
+
# :nocov:
|
88
|
+
end
|
89
|
+
|
90
|
+
declaration_data["type"] = "model"
|
91
|
+
declaration_data["model_base_class"] = "Foobara::Model"
|
92
|
+
declaration_data["attributes_declaration"]["element_type_declarations"][primary_key_attribute]["required"] =
|
93
|
+
true
|
94
|
+
|
95
|
+
declaration_data
|
96
|
+
end
|
57
97
|
end
|
58
98
|
end
|
59
99
|
end
|