lutaml-store 0.2.0 → 0.2.1
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/.rubocop_todo.yml +11 -175
- data/README.adoc +233 -1124
- data/lib/lutaml/store/adapter/base.rb +4 -0
- data/lib/lutaml/store/adapter/memory.rb +8 -0
- data/lib/lutaml/store/cache_store.rb +9 -6
- data/lib/lutaml/store/format.rb +19 -0
- data/lib/lutaml/store/http_cache.rb +3 -13
- data/lib/lutaml/store/model_registration.rb +5 -2
- data/lib/lutaml/store/model_registry.rb +22 -20
- data/lib/lutaml/store/package_store.rb +2 -18
- data/lib/lutaml/store/package_transport/base.rb +48 -0
- data/lib/lutaml/store/package_transport/directory_transport.rb +196 -0
- data/lib/lutaml/store/package_transport/zip_transport.rb +178 -0
- data/lib/lutaml/store/package_transport.rb +11 -438
- data/lib/lutaml/store/version.rb +1 -1
- metadata +12 -77
- data/.github/workflows/main.yml +0 -27
- data/.gitignore +0 -12
- data/CORRECTED_HTTP_CACHE_IMPLEMENTATION.md +0 -209
- data/CORRECTED_HTTP_CACHE_PLAN.md +0 -164
- data/Gemfile +0 -15
- data/Gemfile.lock +0 -227
- data/TODO.impl/0-lutaml-store-self-quality.md +0 -112
- data/TODO.impl/1-lutaml-hal-migration.md +0 -96
- data/TODO.impl/2-glossarist-migration.md +0 -359
- data/TODO.impl/3-lutaml-jsonschema-migration.md +0 -273
- data/bin/console +0 -11
- data/bin/setup +0 -8
- data/demo/Gemfile +0 -15
- data/demo/Gemfile.lock +0 -61
- data/demo/README.adoc +0 -301
- data/demo/data/vcards/co/contact_10_thompson.data +0 -1
- data/demo/data/vcards/co/contact_10_thompson.meta +0 -1
- data/demo/data/vcards/co/contact_1_doe.data +0 -1
- data/demo/data/vcards/co/contact_1_doe.meta +0 -1
- data/demo/data/vcards/co/contact_2_smith.data +0 -1
- data/demo/data/vcards/co/contact_2_smith.meta +0 -1
- data/demo/data/vcards/co/contact_3_johnson.data +0 -1
- data/demo/data/vcards/co/contact_3_johnson.meta +0 -1
- data/demo/data/vcards/co/contact_4_garcia.data +0 -1
- data/demo/data/vcards/co/contact_4_garcia.meta +0 -1
- data/demo/data/vcards/co/contact_5_wilson.data +0 -1
- data/demo/data/vcards/co/contact_5_wilson.meta +0 -1
- data/demo/data/vcards/co/contact_6_brown.data +0 -1
- data/demo/data/vcards/co/contact_6_brown.meta +0 -1
- data/demo/data/vcards/co/contact_7_davis.data +0 -1
- data/demo/data/vcards/co/contact_7_davis.meta +0 -1
- data/demo/data/vcards/co/contact_8_anderson.data +0 -1
- data/demo/data/vcards/co/contact_8_anderson.meta +0 -1
- data/demo/data/vcards/co/contact_9_taylor.data +0 -1
- data/demo/data/vcards/co/contact_9_taylor.meta +0 -1
- data/demo/data/vcards.db +0 -0
- data/demo/pottery_class_demo.rb +0 -164
- data/demo/vcard_models.rb +0 -140
- data/demo/vcard_store_demo.rb +0 -526
- data/lutaml-store.gemspec +0 -36
- data/plan.adoc +0 -606
- data/spec/lutaml/store/adapter_interface_spec.rb +0 -89
- data/spec/lutaml/store/anti_pattern_guard_spec.rb +0 -35
- data/spec/lutaml/store/anti_pattern_spec.rb +0 -78
- data/spec/lutaml/store/autoload_spec.rb +0 -34
- data/spec/lutaml/store/cache_store_spec.rb +0 -271
- data/spec/lutaml/store/compression_spec.rb +0 -78
- data/spec/lutaml/store/config_enhanced_spec.rb +0 -158
- data/spec/lutaml/store/corrected_http_cache_integration_spec.rb +0 -336
- data/spec/lutaml/store/custom_serializer_spec.rb +0 -108
- data/spec/lutaml/store/database_store_spec.rb +0 -279
- data/spec/lutaml/store/file_io_spec.rb +0 -220
- data/spec/lutaml/store/format/yamls_spec.rb +0 -80
- data/spec/lutaml/store/format_round_trip_spec.rb +0 -110
- data/spec/lutaml/store/format_spec.rb +0 -70
- data/spec/lutaml/store/http_cache_entry_spec.rb +0 -203
- data/spec/lutaml/store/http_cache_hal_integration_spec.rb +0 -404
- data/spec/lutaml/store/http_cache_spec.rb +0 -422
- data/spec/lutaml/store/http_header_processor_spec.rb +0 -290
- data/spec/lutaml/store/import_spec.rb +0 -90
- data/spec/lutaml/store/integrity_spec.rb +0 -157
- data/spec/lutaml/store/key_collision_serializer_spec.rb +0 -98
- data/spec/lutaml/store/load_save_spec.rb +0 -107
- data/spec/lutaml/store/lutaml_model_integration_spec.rb +0 -291
- data/spec/lutaml/store/model_serializer_spec.rb +0 -140
- data/spec/lutaml/store/package_definition_spec.rb +0 -89
- data/spec/lutaml/store/package_store_spec.rb +0 -153
- data/spec/lutaml/store/package_transport/directory_transport_spec.rb +0 -139
- data/spec/lutaml/store/package_transport/zip_transport_spec.rb +0 -85
- data/spec/lutaml/store/store_spec.rb +0 -182
- data/spec/lutaml/store_spec.rb +0 -21
- data/spec/spec_helper.rb +0 -16
- data/spec/support/simple_test_model.rb +0 -15
- data/spec/support/yamls_test_model.rb +0 -35
|
@@ -1,449 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "zip"
|
|
4
|
-
require "fileutils"
|
|
5
|
-
|
|
6
3
|
module Lutaml
|
|
7
4
|
module Store
|
|
8
5
|
module PackageTransport
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def write(path, package_store, formats: {})
|
|
15
|
-
raise NotImplementedError
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
def resolve_format(format_name)
|
|
21
|
-
Format.resolve(format_name)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def effective_format(entry, formats)
|
|
25
|
-
formats[entry.model] || entry.default_format
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def format_for_file(filename)
|
|
29
|
-
ext = File.extname(filename)
|
|
30
|
-
case ext
|
|
31
|
-
when ".yaml", ".yml" then Format.resolve(:yaml)
|
|
32
|
-
when ".json" then Format.resolve(:json)
|
|
33
|
-
else Format.resolve(:yaml)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
class DirectoryTransport < Base
|
|
39
|
-
def read(path, package_store, format: nil)
|
|
40
|
-
definition = package_store.definition
|
|
41
|
-
global_format = format
|
|
42
|
-
|
|
43
|
-
read_metadata(path, package_store)
|
|
44
|
-
|
|
45
|
-
definition.model_entries.each do |entry|
|
|
46
|
-
fmt_name = global_format || entry.default_format
|
|
47
|
-
read_model_entry(path, entry, package_store, fmt_name)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
definition.asset_entries.each do |entry|
|
|
51
|
-
read_asset_entry(path, entry, package_store)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def write(path, package_store, formats: {})
|
|
56
|
-
definition = package_store.definition
|
|
57
|
-
FileUtils.mkdir_p(path)
|
|
58
|
-
|
|
59
|
-
write_metadata(path, package_store)
|
|
60
|
-
|
|
61
|
-
definition.model_entries.each do |entry|
|
|
62
|
-
fmt_name = effective_format(entry, formats)
|
|
63
|
-
fmt = resolve_format(fmt_name)
|
|
64
|
-
write_model_entry(path, entry, package_store, fmt)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
definition.asset_entries.each do |entry|
|
|
68
|
-
write_asset_entry(path, entry, package_store)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
private
|
|
73
|
-
|
|
74
|
-
# ── Metadata ──
|
|
75
|
-
|
|
76
|
-
def read_metadata(path, package_store)
|
|
77
|
-
definition = package_store.definition
|
|
78
|
-
return unless definition.metadata_model && definition.metadata_file
|
|
79
|
-
|
|
80
|
-
file_path = File.join(path, definition.metadata_file)
|
|
81
|
-
return unless File.exist?(file_path)
|
|
82
|
-
|
|
83
|
-
fmt = format_for_file(definition.metadata_file)
|
|
84
|
-
raw = File.read(file_path, encoding: "utf-8")
|
|
85
|
-
metadata = fmt.deserialize(raw, definition.metadata_model)
|
|
86
|
-
package_store.metadata = metadata
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def write_metadata(path, package_store)
|
|
90
|
-
return unless package_store.metadata
|
|
91
|
-
|
|
92
|
-
definition = package_store.definition
|
|
93
|
-
fmt = format_for_file(definition.metadata_file)
|
|
94
|
-
content = fmt.serialize(package_store.metadata)
|
|
95
|
-
file_path = File.join(path, definition.metadata_file)
|
|
96
|
-
FileUtils.mkdir_p(File.dirname(file_path))
|
|
97
|
-
File.write(file_path, content, encoding: "utf-8")
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# ── Model entries ──
|
|
101
|
-
|
|
102
|
-
def read_model_entry(base_path, entry, package_store, fmt_name)
|
|
103
|
-
if entry.file
|
|
104
|
-
read_single_file_model(base_path, entry, package_store, fmt_name)
|
|
105
|
-
else
|
|
106
|
-
read_directory_models(base_path, entry, package_store, fmt_name)
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def read_single_file_model(base_path, entry, package_store, fmt_name)
|
|
111
|
-
file_path = File.join(base_path, entry.file)
|
|
112
|
-
return unless File.exist?(file_path)
|
|
113
|
-
|
|
114
|
-
fmt = resolve_format(fmt_name)
|
|
115
|
-
raw = File.read(file_path, encoding: "utf-8")
|
|
116
|
-
model = fmt.deserialize(raw, entry.model)
|
|
117
|
-
package_store.add_model(model)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def read_directory_models(base_path, entry, package_store, fmt_name)
|
|
121
|
-
dir = entry.dir ? File.join(base_path, entry.dir) : base_path
|
|
122
|
-
return unless Dir.exist?(dir)
|
|
123
|
-
|
|
124
|
-
fmt = resolve_format(fmt_name)
|
|
125
|
-
glob = File.join(dir, fmt.glob_pattern)
|
|
126
|
-
|
|
127
|
-
Dir.glob(glob).sort.each do |file_path|
|
|
128
|
-
next unless File.file?(file_path)
|
|
129
|
-
|
|
130
|
-
raw = File.read(file_path, encoding: "utf-8")
|
|
131
|
-
next if raw.strip.empty?
|
|
132
|
-
|
|
133
|
-
begin
|
|
134
|
-
case entry.layout
|
|
135
|
-
when :grouped
|
|
136
|
-
loaded = fmt.deserialize_many(raw, entry.model)
|
|
137
|
-
loaded.each do |m|
|
|
138
|
-
set_key_from_filename(m, file_path, entry)
|
|
139
|
-
package_store.add_model(m)
|
|
140
|
-
end
|
|
141
|
-
else
|
|
142
|
-
model = fmt.deserialize(raw, entry.model)
|
|
143
|
-
set_key_from_filename(model, file_path, entry)
|
|
144
|
-
package_store.add_model(model)
|
|
145
|
-
end
|
|
146
|
-
rescue StandardError => e
|
|
147
|
-
warn "PackageStore: failed to load #{file_path}: #{e.message}"
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def write_model_entry(base_path, entry, package_store, fmt)
|
|
153
|
-
models = package_store.models_for(entry.model)
|
|
154
|
-
return if models.empty?
|
|
155
|
-
|
|
156
|
-
if entry.file
|
|
157
|
-
write_single_file_model(base_path, entry, models, fmt)
|
|
158
|
-
else
|
|
159
|
-
write_directory_models(base_path, entry, models, fmt)
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
def write_single_file_model(base_path, entry, models, fmt)
|
|
164
|
-
content = case entry.layout
|
|
165
|
-
when :grouped
|
|
166
|
-
fmt.serialize_many(models)
|
|
167
|
-
else
|
|
168
|
-
fmt.serialize(models.first)
|
|
169
|
-
end
|
|
170
|
-
file_path = File.join(base_path, entry.file)
|
|
171
|
-
FileUtils.mkdir_p(File.dirname(file_path))
|
|
172
|
-
File.write(file_path, content, encoding: "utf-8")
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def write_directory_models(base_path, entry, models, fmt)
|
|
176
|
-
dir = entry.dir ? File.join(base_path, entry.dir) : base_path
|
|
177
|
-
FileUtils.mkdir_p(dir)
|
|
178
|
-
|
|
179
|
-
case entry.layout
|
|
180
|
-
when :grouped
|
|
181
|
-
grouped = models.group_by { |m| extract_key(m, entry) }
|
|
182
|
-
grouped.each do |key, group|
|
|
183
|
-
file_path = File.join(dir, "#{sanitize_filename(key)}#{fmt.extension}")
|
|
184
|
-
content = fmt.serialize_many(group)
|
|
185
|
-
File.write(file_path, content, encoding: "utf-8")
|
|
186
|
-
end
|
|
187
|
-
else
|
|
188
|
-
models.each do |model|
|
|
189
|
-
key = extract_key(model, entry)
|
|
190
|
-
file_path = File.join(dir, "#{sanitize_filename(key)}#{fmt.extension}")
|
|
191
|
-
content = fmt.serialize(model)
|
|
192
|
-
File.write(file_path, content, encoding: "utf-8")
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
# ── Assets ──
|
|
198
|
-
|
|
199
|
-
def read_asset_entry(base_path, entry, package_store)
|
|
200
|
-
full_path = File.join(base_path, entry.path)
|
|
201
|
-
case entry.type
|
|
202
|
-
when :file
|
|
203
|
-
return unless File.exist?(full_path)
|
|
204
|
-
|
|
205
|
-
package_store.add_asset(entry.path, File.binread(full_path))
|
|
206
|
-
when :directory
|
|
207
|
-
return unless Dir.exist?(full_path)
|
|
208
|
-
|
|
209
|
-
Dir.glob(File.join(full_path, "**", "*")).each do |file|
|
|
210
|
-
next unless File.file?(file)
|
|
211
|
-
|
|
212
|
-
relative = file.sub(%r{\A#{Regexp.escape(base_path)}/}, "")
|
|
213
|
-
package_store.add_asset(relative, File.binread(file))
|
|
214
|
-
end
|
|
215
|
-
end
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
def write_asset_entry(base_path, entry, package_store)
|
|
219
|
-
case entry.type
|
|
220
|
-
when :file
|
|
221
|
-
content = package_store.asset(entry.path)
|
|
222
|
-
return unless content
|
|
223
|
-
|
|
224
|
-
file_path = File.join(base_path, entry.path)
|
|
225
|
-
FileUtils.mkdir_p(File.dirname(file_path))
|
|
226
|
-
File.binwrite(file_path, content)
|
|
227
|
-
when :directory
|
|
228
|
-
package_store.asset_paths
|
|
229
|
-
.select { |p| p.start_with?("#{entry.path}/") }
|
|
230
|
-
.each do |asset_path|
|
|
231
|
-
content = package_store.asset(asset_path)
|
|
232
|
-
next unless content
|
|
233
|
-
|
|
234
|
-
file_path = File.join(base_path, asset_path)
|
|
235
|
-
FileUtils.mkdir_p(File.dirname(file_path))
|
|
236
|
-
File.binwrite(file_path, content)
|
|
237
|
-
end
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
# ── Helpers ──
|
|
242
|
-
|
|
243
|
-
def set_key_from_filename(model, file_path, entry)
|
|
244
|
-
key_value = model.public_send(entry.key)
|
|
245
|
-
return if key_value
|
|
246
|
-
|
|
247
|
-
basename = File.basename(file_path, ".*")
|
|
248
|
-
model.public_send(:"#{entry.key}=", basename)
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
def extract_key(model, entry)
|
|
252
|
-
model.public_send(entry.key).to_s
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
def sanitize_filename(key)
|
|
256
|
-
key.gsub(%r{[/:#?]}, "_")
|
|
257
|
-
end
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
class ZipTransport < Base
|
|
261
|
-
def read(path, package_store, format: nil)
|
|
262
|
-
definition = package_store.definition
|
|
263
|
-
global_format = format
|
|
264
|
-
|
|
265
|
-
Zip::File.open(path) do |zf|
|
|
266
|
-
read_metadata_zip(zf, package_store)
|
|
267
|
-
|
|
268
|
-
definition.model_entries.each do |entry|
|
|
269
|
-
fmt_name = global_format || entry.default_format
|
|
270
|
-
read_model_entry_zip(zf, entry, package_store, fmt_name)
|
|
271
|
-
end
|
|
272
|
-
|
|
273
|
-
definition.asset_entries.each do |entry|
|
|
274
|
-
read_asset_entry_zip(zf, entry, package_store)
|
|
275
|
-
end
|
|
276
|
-
end
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
def write(path, package_store, formats: {})
|
|
280
|
-
definition = package_store.definition
|
|
281
|
-
FileUtils.mkdir_p(File.dirname(path))
|
|
282
|
-
|
|
283
|
-
Zip::File.open(path, create: true) do |zf|
|
|
284
|
-
write_metadata_zip(zf, package_store)
|
|
285
|
-
|
|
286
|
-
definition.model_entries.each do |entry|
|
|
287
|
-
fmt_name = effective_format(entry, formats)
|
|
288
|
-
fmt = resolve_format(fmt_name)
|
|
289
|
-
write_model_entry_zip(zf, entry, package_store, fmt)
|
|
290
|
-
end
|
|
291
|
-
|
|
292
|
-
write_assets_zip(zf, package_store)
|
|
293
|
-
end
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
private
|
|
297
|
-
|
|
298
|
-
# ── Metadata ──
|
|
299
|
-
|
|
300
|
-
def read_metadata_zip(zf, package_store)
|
|
301
|
-
definition = package_store.definition
|
|
302
|
-
return unless definition.metadata_model && definition.metadata_file
|
|
303
|
-
|
|
304
|
-
entry = zf.find_entry(definition.metadata_file)
|
|
305
|
-
return unless entry
|
|
306
|
-
|
|
307
|
-
fmt = format_for_file(definition.metadata_file)
|
|
308
|
-
raw = entry.get_input_stream.read
|
|
309
|
-
metadata = fmt.deserialize(raw, definition.metadata_model)
|
|
310
|
-
package_store.metadata = metadata
|
|
311
|
-
end
|
|
312
|
-
|
|
313
|
-
def write_metadata_zip(zf, package_store)
|
|
314
|
-
return unless package_store.metadata
|
|
315
|
-
|
|
316
|
-
definition = package_store.definition
|
|
317
|
-
fmt = format_for_file(definition.metadata_file)
|
|
318
|
-
content = fmt.serialize(package_store.metadata)
|
|
319
|
-
zf.get_output_stream(definition.metadata_file) { |f| f.write(content) }
|
|
320
|
-
end
|
|
321
|
-
|
|
322
|
-
# ── Model entries ──
|
|
323
|
-
|
|
324
|
-
def read_model_entry_zip(zf, entry, package_store, fmt_name)
|
|
325
|
-
fmt = resolve_format(fmt_name)
|
|
326
|
-
|
|
327
|
-
if entry.file
|
|
328
|
-
read_single_file_zip(zf, entry, package_store, fmt)
|
|
329
|
-
else
|
|
330
|
-
read_directory_zip(zf, entry, package_store, fmt)
|
|
331
|
-
end
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
def read_single_file_zip(zf, entry, package_store, fmt)
|
|
335
|
-
zip_entry = zf.find_entry(entry.file)
|
|
336
|
-
return unless zip_entry
|
|
337
|
-
|
|
338
|
-
raw = zip_entry.get_input_stream.read
|
|
339
|
-
model = fmt.deserialize(raw, entry.model)
|
|
340
|
-
package_store.add_model(model)
|
|
341
|
-
end
|
|
342
|
-
|
|
343
|
-
def read_directory_zip(zf, entry, package_store, fmt)
|
|
344
|
-
prefix = entry.dir ? "#{entry.dir}/" : ""
|
|
345
|
-
|
|
346
|
-
zf.entries.each do |zip_entry|
|
|
347
|
-
next unless zip_entry.name.start_with?(prefix)
|
|
348
|
-
next unless matches_format?(zip_entry.name, fmt)
|
|
349
|
-
next if zip_entry.name == prefix || zip_entry.name.end_with?("/")
|
|
350
|
-
|
|
351
|
-
raw = zip_entry.get_input_stream.read
|
|
352
|
-
next if raw.strip.empty?
|
|
353
|
-
|
|
354
|
-
begin
|
|
355
|
-
loaded = fmt.deserialize_many(raw, entry.model)
|
|
356
|
-
loaded = [loaded] unless loaded.is_a?(Array)
|
|
357
|
-
loaded.each do |m|
|
|
358
|
-
set_key_from_zip_path(m, zip_entry.name, entry, prefix)
|
|
359
|
-
package_store.add_model(m)
|
|
360
|
-
end
|
|
361
|
-
rescue StandardError => e
|
|
362
|
-
warn "PackageStore: failed to load #{zip_entry.name}: #{e.message}"
|
|
363
|
-
end
|
|
364
|
-
end
|
|
365
|
-
end
|
|
366
|
-
|
|
367
|
-
def write_model_entry_zip(zf, entry, package_store, fmt)
|
|
368
|
-
models = package_store.models_for(entry.model)
|
|
369
|
-
return if models.empty?
|
|
370
|
-
|
|
371
|
-
if entry.file
|
|
372
|
-
content = entry.layout == :grouped ? fmt.serialize_many(models) : fmt.serialize(models.first)
|
|
373
|
-
zf.get_output_stream(entry.file) { |f| f.write(content) }
|
|
374
|
-
else
|
|
375
|
-
write_directory_models_zip(zf, entry, models, fmt)
|
|
376
|
-
end
|
|
377
|
-
end
|
|
378
|
-
|
|
379
|
-
def write_directory_models_zip(zf, entry, models, fmt)
|
|
380
|
-
prefix = entry.dir ? "#{entry.dir}/" : ""
|
|
381
|
-
|
|
382
|
-
case entry.layout
|
|
383
|
-
when :grouped
|
|
384
|
-
grouped = models.group_by { |m| extract_key(m, entry) }
|
|
385
|
-
grouped.each do |key, group|
|
|
386
|
-
filename = "#{prefix}#{key}#{fmt.extension}"
|
|
387
|
-
content = fmt.serialize_many(group)
|
|
388
|
-
zf.get_output_stream(filename) { |f| f.write(content) }
|
|
389
|
-
end
|
|
390
|
-
else
|
|
391
|
-
models.each do |model|
|
|
392
|
-
key = extract_key(model, entry)
|
|
393
|
-
filename = "#{prefix}#{key}#{fmt.extension}"
|
|
394
|
-
content = fmt.serialize(model)
|
|
395
|
-
zf.get_output_stream(filename) { |f| f.write(content) }
|
|
396
|
-
end
|
|
397
|
-
end
|
|
398
|
-
end
|
|
399
|
-
|
|
400
|
-
# ── Assets ──
|
|
401
|
-
|
|
402
|
-
def read_asset_entry_zip(zf, entry, package_store)
|
|
403
|
-
case entry.type
|
|
404
|
-
when :file
|
|
405
|
-
zip_entry = zf.find_entry(entry.path)
|
|
406
|
-
package_store.add_asset(entry.path, zip_entry.get_input_stream.read) if zip_entry
|
|
407
|
-
when :directory
|
|
408
|
-
prefix = entry.path.end_with?("/") ? entry.path : "#{entry.path}/"
|
|
409
|
-
zf.entries.each do |zip_entry|
|
|
410
|
-
next unless zip_entry.name.start_with?(prefix)
|
|
411
|
-
next if zip_entry.name == prefix || zip_entry.name.end_with?("/")
|
|
412
|
-
|
|
413
|
-
package_store.add_asset(zip_entry.name, zip_entry.get_input_stream.read)
|
|
414
|
-
end
|
|
415
|
-
end
|
|
416
|
-
end
|
|
417
|
-
|
|
418
|
-
def write_assets_zip(zf, package_store)
|
|
419
|
-
package_store.asset_paths.each do |asset_path|
|
|
420
|
-
content = package_store.asset(asset_path)
|
|
421
|
-
zf.get_output_stream(asset_path) { |f| f.write(content) } if content
|
|
422
|
-
end
|
|
423
|
-
end
|
|
424
|
-
|
|
425
|
-
# ── Helpers ──
|
|
426
|
-
|
|
427
|
-
def set_key_from_zip_path(model, zip_path, entry, prefix)
|
|
428
|
-
key_value = model.public_send(entry.key)
|
|
429
|
-
return if key_value
|
|
430
|
-
|
|
431
|
-
filename = zip_path.sub(prefix, "")
|
|
432
|
-
basename = File.basename(filename, ".*")
|
|
433
|
-
model.public_send(:"#{entry.key}=", basename)
|
|
434
|
-
end
|
|
6
|
+
autoload :Base, "lutaml/store/package_transport/base"
|
|
7
|
+
autoload :DirectoryTransport, "lutaml/store/package_transport/directory_transport"
|
|
8
|
+
autoload :ZipTransport, "lutaml/store/package_transport/zip_transport"
|
|
435
9
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
10
|
+
TRANSPORTS = {
|
|
11
|
+
directory: "DirectoryTransport",
|
|
12
|
+
zip: "ZipTransport"
|
|
13
|
+
}.freeze
|
|
439
14
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
return true if fmt.extension == ".yaml" && ext == ".yml"
|
|
15
|
+
def self.resolve(transport)
|
|
16
|
+
entry = TRANSPORTS[transport.to_sym]
|
|
17
|
+
raise ConfigurationError, "Unknown transport: #{transport}" unless entry
|
|
444
18
|
|
|
445
|
-
|
|
446
|
-
end
|
|
19
|
+
const_get(entry).new
|
|
447
20
|
end
|
|
448
21
|
end
|
|
449
22
|
end
|
data/lib/lutaml/store/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lutaml-store
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ronald Tse
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: exe
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-06-05 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: lutaml-model
|
|
@@ -47,52 +48,13 @@ executables: []
|
|
|
47
48
|
extensions: []
|
|
48
49
|
extra_rdoc_files: []
|
|
49
50
|
files:
|
|
50
|
-
- ".github/workflows/main.yml"
|
|
51
|
-
- ".gitignore"
|
|
52
51
|
- ".rspec"
|
|
53
52
|
- ".rubocop.yml"
|
|
54
53
|
- ".rubocop_todo.yml"
|
|
55
54
|
- CLAUDE.md
|
|
56
55
|
- CODE_OF_CONDUCT.md
|
|
57
|
-
- CORRECTED_HTTP_CACHE_IMPLEMENTATION.md
|
|
58
|
-
- CORRECTED_HTTP_CACHE_PLAN.md
|
|
59
|
-
- Gemfile
|
|
60
|
-
- Gemfile.lock
|
|
61
56
|
- README.adoc
|
|
62
57
|
- Rakefile
|
|
63
|
-
- TODO.impl/0-lutaml-store-self-quality.md
|
|
64
|
-
- TODO.impl/1-lutaml-hal-migration.md
|
|
65
|
-
- TODO.impl/2-glossarist-migration.md
|
|
66
|
-
- TODO.impl/3-lutaml-jsonschema-migration.md
|
|
67
|
-
- bin/console
|
|
68
|
-
- bin/setup
|
|
69
|
-
- demo/Gemfile
|
|
70
|
-
- demo/Gemfile.lock
|
|
71
|
-
- demo/README.adoc
|
|
72
|
-
- demo/data/vcards.db
|
|
73
|
-
- demo/data/vcards/co/contact_10_thompson.data
|
|
74
|
-
- demo/data/vcards/co/contact_10_thompson.meta
|
|
75
|
-
- demo/data/vcards/co/contact_1_doe.data
|
|
76
|
-
- demo/data/vcards/co/contact_1_doe.meta
|
|
77
|
-
- demo/data/vcards/co/contact_2_smith.data
|
|
78
|
-
- demo/data/vcards/co/contact_2_smith.meta
|
|
79
|
-
- demo/data/vcards/co/contact_3_johnson.data
|
|
80
|
-
- demo/data/vcards/co/contact_3_johnson.meta
|
|
81
|
-
- demo/data/vcards/co/contact_4_garcia.data
|
|
82
|
-
- demo/data/vcards/co/contact_4_garcia.meta
|
|
83
|
-
- demo/data/vcards/co/contact_5_wilson.data
|
|
84
|
-
- demo/data/vcards/co/contact_5_wilson.meta
|
|
85
|
-
- demo/data/vcards/co/contact_6_brown.data
|
|
86
|
-
- demo/data/vcards/co/contact_6_brown.meta
|
|
87
|
-
- demo/data/vcards/co/contact_7_davis.data
|
|
88
|
-
- demo/data/vcards/co/contact_7_davis.meta
|
|
89
|
-
- demo/data/vcards/co/contact_8_anderson.data
|
|
90
|
-
- demo/data/vcards/co/contact_8_anderson.meta
|
|
91
|
-
- demo/data/vcards/co/contact_9_taylor.data
|
|
92
|
-
- demo/data/vcards/co/contact_9_taylor.meta
|
|
93
|
-
- demo/pottery_class_demo.rb
|
|
94
|
-
- demo/vcard_models.rb
|
|
95
|
-
- demo/vcard_store_demo.rb
|
|
96
58
|
- lib/lutaml/store.rb
|
|
97
59
|
- lib/lutaml/store/adapter.rb
|
|
98
60
|
- lib/lutaml/store/adapter/base.rb
|
|
@@ -127,49 +89,21 @@ files:
|
|
|
127
89
|
- lib/lutaml/store/package_definition.rb
|
|
128
90
|
- lib/lutaml/store/package_store.rb
|
|
129
91
|
- lib/lutaml/store/package_transport.rb
|
|
92
|
+
- lib/lutaml/store/package_transport/base.rb
|
|
93
|
+
- lib/lutaml/store/package_transport/directory_transport.rb
|
|
94
|
+
- lib/lutaml/store/package_transport/zip_transport.rb
|
|
130
95
|
- lib/lutaml/store/storage_key.rb
|
|
131
96
|
- lib/lutaml/store/version.rb
|
|
132
|
-
- lutaml-store.gemspec
|
|
133
|
-
- plan.adoc
|
|
134
97
|
- sig/lutaml/store.rbs
|
|
135
|
-
- spec/lutaml/store/adapter_interface_spec.rb
|
|
136
|
-
- spec/lutaml/store/anti_pattern_guard_spec.rb
|
|
137
|
-
- spec/lutaml/store/anti_pattern_spec.rb
|
|
138
|
-
- spec/lutaml/store/autoload_spec.rb
|
|
139
|
-
- spec/lutaml/store/cache_store_spec.rb
|
|
140
|
-
- spec/lutaml/store/compression_spec.rb
|
|
141
|
-
- spec/lutaml/store/config_enhanced_spec.rb
|
|
142
|
-
- spec/lutaml/store/corrected_http_cache_integration_spec.rb
|
|
143
|
-
- spec/lutaml/store/custom_serializer_spec.rb
|
|
144
|
-
- spec/lutaml/store/database_store_spec.rb
|
|
145
|
-
- spec/lutaml/store/file_io_spec.rb
|
|
146
|
-
- spec/lutaml/store/format/yamls_spec.rb
|
|
147
|
-
- spec/lutaml/store/format_round_trip_spec.rb
|
|
148
|
-
- spec/lutaml/store/format_spec.rb
|
|
149
|
-
- spec/lutaml/store/http_cache_entry_spec.rb
|
|
150
|
-
- spec/lutaml/store/http_cache_hal_integration_spec.rb
|
|
151
|
-
- spec/lutaml/store/http_cache_spec.rb
|
|
152
|
-
- spec/lutaml/store/http_header_processor_spec.rb
|
|
153
|
-
- spec/lutaml/store/import_spec.rb
|
|
154
|
-
- spec/lutaml/store/integrity_spec.rb
|
|
155
|
-
- spec/lutaml/store/key_collision_serializer_spec.rb
|
|
156
|
-
- spec/lutaml/store/load_save_spec.rb
|
|
157
|
-
- spec/lutaml/store/lutaml_model_integration_spec.rb
|
|
158
|
-
- spec/lutaml/store/model_serializer_spec.rb
|
|
159
|
-
- spec/lutaml/store/package_definition_spec.rb
|
|
160
|
-
- spec/lutaml/store/package_store_spec.rb
|
|
161
|
-
- spec/lutaml/store/package_transport/directory_transport_spec.rb
|
|
162
|
-
- spec/lutaml/store/package_transport/zip_transport_spec.rb
|
|
163
|
-
- spec/lutaml/store/store_spec.rb
|
|
164
|
-
- spec/lutaml/store_spec.rb
|
|
165
|
-
- spec/spec_helper.rb
|
|
166
|
-
- spec/support/simple_test_model.rb
|
|
167
|
-
- spec/support/yamls_test_model.rb
|
|
168
98
|
homepage: https://github.com/lutaml/lutaml-store
|
|
169
99
|
licenses:
|
|
170
100
|
- BSD-2-Clause
|
|
171
101
|
metadata:
|
|
102
|
+
homepage_uri: https://github.com/lutaml/lutaml-store
|
|
103
|
+
source_code_uri: https://github.com/lutaml/lutaml-store
|
|
104
|
+
changelog_uri: https://github.com/lutaml/lutaml-store
|
|
172
105
|
rubygems_mfa_required: 'true'
|
|
106
|
+
post_install_message:
|
|
173
107
|
rdoc_options: []
|
|
174
108
|
require_paths:
|
|
175
109
|
- lib
|
|
@@ -184,7 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
184
118
|
- !ruby/object:Gem::Version
|
|
185
119
|
version: '0'
|
|
186
120
|
requirements: []
|
|
187
|
-
rubygems_version: 3.
|
|
121
|
+
rubygems_version: 3.5.22
|
|
122
|
+
signing_key:
|
|
188
123
|
specification_version: 4
|
|
189
124
|
summary: Store-centric database-style API for Lutaml::Model with multi-backend persistence.
|
|
190
125
|
test_files: []
|
data/.github/workflows/main.yml
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
name: Ruby
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- main
|
|
7
|
-
|
|
8
|
-
pull_request:
|
|
9
|
-
|
|
10
|
-
jobs:
|
|
11
|
-
build:
|
|
12
|
-
runs-on: ubuntu-latest
|
|
13
|
-
name: Ruby ${{ matrix.ruby }}
|
|
14
|
-
strategy:
|
|
15
|
-
matrix:
|
|
16
|
-
ruby:
|
|
17
|
-
- '3.3.2'
|
|
18
|
-
|
|
19
|
-
steps:
|
|
20
|
-
- uses: actions/checkout@v4
|
|
21
|
-
- name: Set up Ruby
|
|
22
|
-
uses: ruby/setup-ruby@v1
|
|
23
|
-
with:
|
|
24
|
-
ruby-version: ${{ matrix.ruby }}
|
|
25
|
-
bundler-cache: true
|
|
26
|
-
- name: Run the default task
|
|
27
|
-
run: bundle exec rake
|