suma 0.5.31 → 0.5.32

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 988b5f4b9f5dd2979ce2b2b38d58b81a26c28deea570d1ef81521c38b213f289
4
- data.tar.gz: b311e9bfbec6e5744d9c1b903d67da6152f4c0e09037158280db52d0ee225a67
3
+ metadata.gz: e58de844e84a98a6114627866bee6a97f6e9b77b17e4b14f8086a9f38085436c
4
+ data.tar.gz: 907a991943cd782e14da96bd6579937ab382c75e0b332cf3ec55ec3ee7d649aa
5
5
  SHA512:
6
- metadata.gz: 112f94d3a4af0a568e46bf17511f635902c4b6397686b723ba1dabf0d1f5e3472c2f84164d281eac1154d3b606600dc3eaf41d8044966b07c3cc7b232b8d77cb
7
- data.tar.gz: 8dfaa618a8ae1ad12761fb47c43d669bab381d002839e9129e2785fb6e407df765110924df99f23cac929855e49669d4c5c8ab2e8890f05b991aca458424a81d
6
+ metadata.gz: df779c2bda89b8e69bc56fac088acb60d734072522a239e9cc1879389707b53d21bf115897d2550708e9b1b2a53586b05fa533d12f52f5abc2d50efda02b0f1b
7
+ data.tar.gz: f99cf892fd49bf72f1f02bc3821202fabdc16ef82486fd6cdd7af9ca7e294de2343e36e41b0c3616f598989d67e679d5b03bfb3d80bccd013276954a5dc85d13
@@ -300,33 +300,97 @@ module Suma
300
300
  end
301
301
 
302
302
  # The schema an imported declaration is declared in, resolved through
303
- # +schema+'s interfaces — the same resolution the source remark xrefs
304
- # carry: a local declaration wins; then a USE FROM item naming the
305
- # declaration; then a single bare USE FROM. nil leaves the citation
306
- # unqualified-with-owner, since inventing an owner would be wrong
307
- # (iso-10303#835: the citing schema is not the declaring schema).
303
+ # +schema+'s USE-FROM closure — the same resolution the source remark
304
+ # xrefs carry: a local declaration wins; otherwise the USE FROM edges
305
+ # (item-naming ones first, then bare ones) are walked transitively,
306
+ # and a single distinct declaring schema wins. nil leaves the citation
307
+ # qualified with the citing schema, since inventing an owner would be
308
+ # wrong (iso-10303#835: the declarer can sit more than one USE FROM
309
+ # away, and sibling branches must all be searched before settling).
308
310
  def declaring_schema_id(schema, entity_id)
309
- return schema.id if schema.entities.any? { |e| e.id == entity_id }
311
+ declarers = declaring_schemas(schema, entity_id, [])
312
+ declarers.uniq.one? ? declarers.first : nil
313
+ end
314
+
315
+ # Distinct schema ids within +schema+'s USE-FROM closure declaring
316
+ # +entity_id+. An interface whose item list names the declaration
317
+ # claims it outright (that is what the item list means in EXPRESS) —
318
+ # those sources are terminal candidates. Bare USE FROMs carry no
319
+ # claim, so they are walked; a bare source outside the manifest
320
+ # cannot be verified and stands as its own candidate. Each branch
321
+ # tracks its own visited list so sibling imports are searched
322
+ # independently; re-entering a schema on the same branch ends it.
323
+ def declaring_schemas(schema, entity_id, visited)
324
+ return [] if visited.include?(schema.id)
325
+
326
+ visited << schema.id
327
+ return [schema.id] if schema.entities.any? { |e| e.id == entity_id }
328
+
329
+ item_matches, bare_sources = use_from_sources(schema, entity_id)
330
+ return item_matches.uniq if item_matches.any?
331
+
332
+ walk_bare_sources(bare_sources, entity_id, visited)
333
+ end
310
334
 
335
+ def walk_bare_sources(bare_sources, entity_id, visited)
336
+ bare_sources.uniq.flat_map do |source|
337
+ loaded = loaded_schema(source)
338
+ if loaded
339
+ declaring_schemas(loaded, entity_id, visited.dup)
340
+ else
341
+ [source]
342
+ end
343
+ end
344
+ end
345
+
346
+ # The USE FROM interfaces of +schema+ relevant to +entity_id+: the
347
+ # sources whose item list names it, and the bare USE FROM sources.
348
+ def use_from_sources(schema, entity_id)
311
349
  item_matches = []
312
350
  bare_sources = []
313
351
  schema.interfaces.each do |interface|
314
- source = interface.schema&.id
315
- next unless source && interface.kind == "USE"
316
-
317
- items = Array(interface.items)
318
- if items.empty?
319
- bare_sources << source
320
- elsif items.any? { |item| import_item_id(item) == entity_id }
321
- item_matches << source
352
+ case interface_claim(interface, entity_id)
353
+ when :item then item_matches << interface.schema.id
354
+ when :bare then bare_sources << interface.schema.id
322
355
  end
323
356
  end
324
357
 
325
- if item_matches.uniq.one?
326
- item_matches.first
327
- elsif item_matches.empty? && bare_sources.uniq.one?
328
- bare_sources.first
329
- end
358
+ [item_matches, bare_sources]
359
+ end
360
+
361
+ # :item when the interface's item list names the declaration, :bare
362
+ # for a bare USE FROM, nil when the interface is irrelevant to it.
363
+ def interface_claim(interface, entity_id)
364
+ source = interface.schema&.id
365
+ return nil unless source && interface.kind == "USE"
366
+
367
+ items = Array(interface.items)
368
+ return :bare if items.empty?
369
+ return :item if item_names?(items, entity_id)
370
+
371
+ nil
372
+ end
373
+
374
+ def item_names?(items, entity_id)
375
+ items.any? { |item| import_item_id(item) == entity_id }
376
+ end
377
+
378
+ # Sibling schema by EXPRESS id, parsed on demand from the schema
379
+ # manifest and memoized — the walk only touches schemas a citation
380
+ # chain actually names.
381
+ def loaded_schema(id)
382
+ @loaded_schemas ||= {}
383
+ return @loaded_schemas[id] if @loaded_schemas.key?(id)
384
+
385
+ path = schema_manifest_paths[id]
386
+ @loaded_schemas[id] =
387
+ path && Expressir::Express::Parser.from_file(path)&.schemas&.first
388
+ end
389
+
390
+ def schema_manifest_paths
391
+ @schema_manifest_paths ||=
392
+ Expressir::SchemaManifest.from_file(@schema_manifest_file).schemas
393
+ .to_h { |entry| [entry.id, entry.path] }
330
394
  end
331
395
 
332
396
  # The imported declaration's name as written in the USE FROM list:
data/lib/suma/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Suma
4
- VERSION = "0.5.31"
4
+ VERSION = "0.5.32"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: suma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.31
4
+ version: 0.5.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.