Class: Expressir::Manifest::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/expressir/manifest/resolver.rb

Overview

Resolves schema paths in manifests using pattern-based path discovery Attempts to find file paths for schemas with missing or empty paths

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest, options = {}) ⇒ Resolver

Initialize resolver

Parameters:

  • manifest (SchemaManifest)

    The manifest to resolve

  • options (Hash) (defaults to: {})

    Resolution options

Options Hash (options):

  • :base_dirs (Array<String>)

    Base directories to search

  • :verbose (Boolean)

    Enable verbose output



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/expressir/manifest/resolver.rb', line 17

def initialize(manifest, options = {})
  @manifest = manifest
  @options = options
  @base_dirs = extract_base_dirs_from_manifest

  # Override with explicit base_dirs if provided
  if options[:base_dirs]
    @base_dirs = Array(options[:base_dirs]).map do |d|
      File.expand_path(d)
    end
  end
end

Instance Attribute Details

#base_dirsObject (readonly)

Returns the value of attribute base_dirs.



10
11
12
# File 'lib/expressir/manifest/resolver.rb', line 10

def base_dirs
  @base_dirs
end

#manifestObject (readonly)

Returns the value of attribute manifest.



10
11
12
# File 'lib/expressir/manifest/resolver.rb', line 10

def manifest
  @manifest
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/expressir/manifest/resolver.rb', line 10

def options
  @options
end

Instance Method Details

#resolve_pathsSchemaManifest

Resolve paths for all schemas in manifest Works like manifest create - resolves all dependencies from schemas with paths

Returns:

  • (SchemaManifest)

    New manifest with resolved paths and dependencies



33
34
35
36
37
38
39
40
41
42
43
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/expressir/manifest/resolver.rb', line 33

def resolve_paths
  # Create new manifest to avoid modifying original
  resolved_manifest = SchemaManifest.new

  # Track all resolved schema paths
  all_resolved_paths = Set.new
  all_unresolved = []

  # Find schemas with valid paths to use as roots
  root_schemas = manifest.schemas.select do |s|
    !s.path.nil? && !s.path.empty? && File.exist?(s.path)
  end

  if root_schemas.empty?
    # No roots, just try to resolve individual schemas
    say "No valid schema paths found, attempting simple path resolution..." if options[:verbose]
    return resolve_paths_simple
  end

  say "Resolving dependencies from #{root_schemas.size} root schema(s)..." if options[:verbose]
  say_base_dirs

  # For each root schema, resolve all its dependencies
  root_schemas.each do |root_entry|
    resolver = Model::DependencyResolver.new(
      base_dirs: @base_dirs,
      schema_registry: build_schema_registry,
      verbose: options[:verbose],
    )

    # Resolve all dependencies for this root
    resolved_paths = resolver.resolve_dependencies(root_entry.path)
    all_resolved_paths.merge(resolved_paths)
    all_unresolved.concat(resolver.unresolved)
  end

  # Add all resolved schemas to manifest
  all_resolved_paths.each do |path|
    schema_id = extract_schema_name(path)
    resolved_manifest.schemas << SchemaManifestEntry.new(
      id: schema_id,
      path: path,
    )
  end

  # Add unresolved schemas with empty paths
  all_unresolved.uniq { |e| e[:schema_name] }.each do |entry|
    # Only add if not already in manifest
    unless resolved_manifest.schemas.any? do |s|
      s.id == entry[:schema_name]
    end
      resolved_manifest.schemas << SchemaManifestEntry.new(
        id: entry[:schema_name],
        path: "",
      )
    end
  end

  resolved_manifest
end

#resolve_paths_simpleSchemaManifest

Simple path resolution - just try to find missing paths Used when no valid root schemas are available

Returns:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/expressir/manifest/resolver.rb', line 97

def resolve_paths_simple
  resolved_manifest = SchemaManifest.new

  resolver = Model::DependencyResolver.new(
    base_dirs: @base_dirs,
    schema_registry: build_schema_registry,
    verbose: options[:verbose],
  )

  manifest.schemas.each do |schema_entry|
    resolved_entry = resolve_schema_entry(schema_entry, resolver)
    resolved_manifest.schemas << resolved_entry
  end

  resolved_manifest
end

#statisticsHash

Get resolution statistics

Returns:

  • (Hash)

    Resolution statistics



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/expressir/manifest/resolver.rb', line 116

def statistics
  unresolved_count = manifest.schemas.count do |s|
    s.path.nil? || s.path.empty?
  end
  {
    total_schemas: manifest.schemas.size,
    resolved: manifest.schemas.size - unresolved_count,
    unresolved: unresolved_count,
    base_dirs: @base_dirs,
  }
end