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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '06594c54e2d31ffa36c92ff55fd09287bfb56c241e68c5200874874772fb12d0'
4
- data.tar.gz: 7dac9df9efd8d6809b9dbe781674173f59b9151c4dba8c88de1e3dbe0f859118
3
+ metadata.gz: 74a7b47ff503e5d7bf90b2100497e1c07998efda26baf2f2ea0d7bdab3f978b8
4
+ data.tar.gz: 0c78bac42ce7fb38c9d5362d73827786148421e27c2ff0425e4c6a8875a0dbf9
5
5
  SHA512:
6
- metadata.gz: dbdf6ccb93791927cefb3b1e8aae1a7a2caadfe58cb2c11a703853e13297140cd4e25b543f0e333f8f1dcd7063c80bdae0f00e82628f0db8c5bcbf319273191c
7
- data.tar.gz: 1c76bdd14f2589e68f812696cf796c7a7d01525ca9461ced5fa3853a19692cb733f97e2890ca7a0e54bab493eb9ca9235811817387f2f13a71a99604013af814
6
+ metadata.gz: 7f2dc5b69968131bf1e5588c861e9a2cfa25bf6dd394b2a3e76090ed54ea86feef3ad8ee936ff4872d90a5fb83adcdd93b323ca9337fb64afc8f6ebf37d32579
7
+ data.tar.gz: e26f245c4dcf3b66d9b5683e89beef8a30c5df19688afb4de2653c569dd5be0ae6d330a59a1a28ef8a3c9973b9fd6a169ce88928a0ae777aba24f7df071a5925
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.3] - 2024-12-03
2
+
3
+ - Convert entities into models
4
+
1
5
  ## [0.0.2] - 2024-12-02
2
6
 
3
7
  - Release as a gem
@@ -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
- type = domain.foobara_type_from_strict_stringified_declaration(manifest_to_import.declaration_data)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-remote-imports
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi