foobara-remote-imports 0.0.1 → 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: 303316f5bfc4dd44fe0e436894e38f01bab94497a890742558823dfe0f82459f
4
- data.tar.gz: 0e22fb8f9708b786d9b9732c47e94284e5c8b97f2eb330b22069f9db77d98019
3
+ metadata.gz: 74a7b47ff503e5d7bf90b2100497e1c07998efda26baf2f2ea0d7bdab3f978b8
4
+ data.tar.gz: 0c78bac42ce7fb38c9d5362d73827786148421e27c2ff0425e4c6a8875a0dbf9
5
5
  SHA512:
6
- metadata.gz: 78d3271c3ff89a58ed0d5e0bf95cf61b982cb26036796702c691847a1ad215ec1d22022a00d80863a5713b23b4870906dd3fae806eb3d21b69cb53da68fb0cb6
7
- data.tar.gz: 57592151a69f9c3852f3b74ae6a76acaaa00ab1390b963bee67b89536faf14f35bdb618c642f474822cde8689c6701e9eb25e4e3e629fee55bc7eaae7b2097ba
6
+ metadata.gz: 7f2dc5b69968131bf1e5588c861e9a2cfa25bf6dd394b2a3e76090ed54ea86feef3ad8ee936ff4872d90a5fb83adcdd93b323ca9337fb64afc8f6ebf37d32579
7
+ data.tar.gz: e26f245c4dcf3b66d9b5683e89beef8a30c5df19688afb4de2653c569dd5be0ae6d330a59a1a28ef8a3c9973b9fd6a169ce88928a0ae777aba24f7df071a5925
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- ## [0.0.1] - 2024-12-02
1
+ ## [0.0.3] - 2024-12-03
2
+
3
+ - Convert entities into models
4
+
5
+ ## [0.0.2] - 2024-12-02
2
6
 
3
7
  - Release as a gem
4
8
 
@@ -1,4 +1,5 @@
1
1
  require "digest/md5"
2
+ require "fileutils"
2
3
  require "json"
3
4
  require "net/http"
4
5
 
@@ -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.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi