Class: Suma::SchemaComparer

Inherits:
Object
  • Object
show all
Defined in:
lib/suma/schema_comparer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trial_schema, reference_schema, options = {}) ⇒ SchemaComparer

Returns a new instance of SchemaComparer.



12
13
14
15
16
# File 'lib/suma/schema_comparer.rb', line 12

def initialize(trial_schema, reference_schema, options = {})
  @trial_schema = trial_schema
  @reference_schema = reference_schema
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/suma/schema_comparer.rb', line 10

def options
  @options
end

#reference_schemaObject (readonly)

Returns the value of attribute reference_schema.



10
11
12
# File 'lib/suma/schema_comparer.rb', line 10

def reference_schema
  @reference_schema
end

#trial_schemaObject (readonly)

Returns the value of attribute trial_schema.



10
11
12
# File 'lib/suma/schema_comparer.rb', line 10

def trial_schema
  @trial_schema
end

Instance Method Details

#compareObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/suma/schema_comparer.rb', line 18

def compare
  validate_inputs

  trial_stepmod = options[:trial_stepmod] || detect_repo_root(trial_schema)
  reference_stepmod = options[:reference_stepmod] || detect_repo_root(reference_schema)

  out_dir = Dir.mktmpdir("eengine-compare-")

  result = Eengine::Wrapper.compare(
    trial_schema,
    reference_schema,
    mode: options[:mode] || "resource",
    trial_stepmod: trial_stepmod,
    reference_stepmod: reference_stepmod,
    out_dir: out_dir,
  )

  unless result[:has_changes]
    FileUtils.rm_rf(out_dir) if File.directory?(out_dir)
    return nil
  end

  raise Suma::CompilationError, "XML output not found" unless result[:xml_path]

  convert_to_change_yaml(result[:xml_path], out_dir)
ensure
  FileUtils.rm_rf(out_dir) if out_dir && File.directory?(out_dir)
end