Class: Lutaml::Xsd::PackageConflictResolver

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

Overview

Service class for resolving conflicts

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conflict_report, package_sources) ⇒ PackageConflictResolver

Returns a new instance of PackageConflictResolver.



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

def initialize(conflict_report, package_sources)
  @conflict_report = conflict_report
  @package_sources = package_sources.sort_by(&:priority)
end

Instance Attribute Details

#conflict_reportObject (readonly)

Returns the value of attribute conflict_report.



7
8
9
# File 'lib/lutaml/xsd/package_conflict_resolver.rb', line 7

def conflict_report
  @conflict_report
end

#package_sourcesObject (readonly)

Returns the value of attribute package_sources.



7
8
9
# File 'lib/lutaml/xsd/package_conflict_resolver.rb', line 7

def package_sources
  @package_sources
end

Instance Method Details

#resolveArray<PackageSource>

Resolve conflicts and determine load order

Returns:

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/lutaml/xsd/package_conflict_resolver.rb', line 17

def resolve
  error_strategy_sources = @package_sources.select do |s|
    s.conflict_resolution == "error"
  end

  if error_strategy_sources.any? && @conflict_report.has_conflicts?
    raise PackageMergeError.new(
      message: "Conflicts detected with 'error' resolution strategy",
      conflict_report: @conflict_report,
      error_strategy_sources: error_strategy_sources,
    )
  end

  @package_sources
end

#resolve_conflict(conflict) ⇒ Object

Determine winner for a specific conflict



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/lutaml/xsd/package_conflict_resolver.rb', line 34

def resolve_conflict(conflict)
  sources = case conflict
            when Conflicts::NamespaceConflict, Conflicts::TypeConflict
              conflict.sources
            when Conflicts::SchemaConflict
              conflict.source_files.filter_map do |fs|
                @package_sources.find do |ps|
                  ps.package_path == fs.package_path
                end
              end
            end

  resolve_by_priority(sources)
end