Class: Expressir::Manifest::Resolver
- Inherits:
-
Object
- Object
- Expressir::Manifest::Resolver
- 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
-
#base_dirs ⇒ Object
readonly
Returns the value of attribute base_dirs.
-
#manifest ⇒ Object
readonly
Returns the value of attribute manifest.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(manifest, options = {}) ⇒ Resolver
constructor
Initialize resolver.
-
#resolve_paths ⇒ SchemaManifest
Resolve paths for all schemas in manifest Works like manifest create - resolves all dependencies from schemas with paths.
-
#resolve_paths_simple ⇒ SchemaManifest
Simple path resolution - just try to find missing paths Used when no valid root schemas are available.
-
#statistics ⇒ Hash
Get resolution statistics.
Constructor Details
#initialize(manifest, options = {}) ⇒ Resolver
Initialize resolver
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/expressir/manifest/resolver.rb', line 17 def initialize(manifest, = {}) @manifest = manifest @options = @base_dirs = extract_base_dirs_from_manifest # Override with explicit base_dirs if provided if [:base_dirs] @base_dirs = Array([:base_dirs]).map do |d| File.(d) end end end |
Instance Attribute Details
#base_dirs ⇒ Object (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 |
#manifest ⇒ Object (readonly)
Returns the value of attribute manifest.
10 11 12 |
# File 'lib/expressir/manifest/resolver.rb', line 10 def manifest @manifest end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/expressir/manifest/resolver.rb', line 10 def @options end |
Instance Method Details
#resolve_paths ⇒ SchemaManifest
Resolve paths for all schemas in manifest Works like manifest create - resolves all dependencies from schemas with paths
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 [:verbose] return resolve_paths_simple end say "Resolving dependencies from #{root_schemas.size} root schema(s)..." if [: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: [: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_simple ⇒ SchemaManifest
Simple path resolution - just try to find missing paths Used when no valid root schemas are available
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: [:verbose], ) manifest.schemas.each do |schema_entry| resolved_entry = resolve_schema_entry(schema_entry, resolver) resolved_manifest.schemas << resolved_entry end resolved_manifest end |
#statistics ⇒ Hash
Get 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 |