Class: Lutaml::Xsd::EntrypointIdentifier

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xsd/entrypoint_identifier.rb

Overview

Identifies entrypoint schemas in a package Entrypoints are schemas that are explicitly listed as entry files in the package metadata

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package) ⇒ EntrypointIdentifier

Returns a new instance of EntrypointIdentifier.

Parameters:



12
13
14
# File 'lib/lutaml/xsd/entrypoint_identifier.rb', line 12

def initialize(package)
  @package = package
end

Instance Attribute Details

#packageObject (readonly)

Returns the value of attribute package.



9
10
11
# File 'lib/lutaml/xsd/entrypoint_identifier.rb', line 9

def package
  @package
end

Instance Method Details

#get_dependenciesArray<Hash>

Get all dependencies for entrypoints

Returns:

  • (Array<Hash>)

    Array of dependency info hashes



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/lutaml/xsd/entrypoint_identifier.rb', line 44

def get_dependencies
  # Get metadata from package
  validation = package.validate
   = validation.

  package.load_repository
  all_schemas = Lutaml::Xml::Schema::Xsd::Schema.processed_schemas

  # Exclude entrypoint files from dependencies
  entrypoint_files = &.[]("files") || []
  entrypoint_paths = Set.new(entrypoint_files.map do |f|
    File.basename(f)
  end)

  dependencies = []
  all_schemas.each do |location, schema|
    basename = File.basename(location)
    next if entrypoint_paths.include?(basename)

    dependencies << {
      file: basename,
      path: location,
      namespace: schema.target_namespace,
      schema: schema,
    }
  end

  dependencies
end

#identify_entrypointsArray<Hash>

Identify entrypoint schemas

Returns:

  • (Array<Hash>)

    Array of entrypoint info hashes



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lutaml/xsd/entrypoint_identifier.rb', line 18

def identify_entrypoints
  # Get metadata from package first, before loading repository
  validation = package.validate
   = validation.

  entrypoint_files = &.[]("files") || []

  # Now load repository to get schemas
  repository = package.load_repository

  entrypoint_files.filter_map do |file_path|
    schema = find_schema_by_path(repository, file_path)
    next unless schema

    {
      file: File.basename(file_path),
      path: file_path,
      namespace: schema.target_namespace,
      schema: schema,
      role: "Root schema",
    }
  end
end