Class: Modspec::Suite

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/modspec/suite.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_yaml_files(*files) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/modspec/suite.rb', line 83

def self.from_yaml_files(*files)
  combined_suite = new
  files.each do |file|
    suite = from_yaml(File.read(file))
    combined_suite = combined_suite.combine(suite)
  end
  combined_suite.name = "Combined Suite"
  combined_suite
end

Instance Method Details

#all_identifiersObject



72
73
74
# File 'lib/modspec/suite.rb', line 72

def all_identifiers
  statement_index.keys
end

#combine(other_suite) ⇒ Object



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
# File 'lib/modspec/suite.rb', line 36

def combine(other_suite)
  unless other_suite.is_a?(Modspec::Suite)
    raise ArgumentError,
          "Argument must be a Modspec::Suite"
  end

  combined_suite = dup
  combined_suite.reset_statement_index
  if other_suite.normative_statements_classes
    combined_suite.normative_statements_classes ||= []
    combined_suite.normative_statements_classes += other_suite.normative_statements_classes
  end

  if other_suite.conformance_classes
    combined_suite.conformance_classes ||= []
    combined_suite.conformance_classes += other_suite.conformance_classes
  end

  # Ensure uniqueness of identifiers
  combined_suite.normative_statements_classes&.uniq!(&:identifier)

  combined_suite.conformance_classes&.uniq!(&:identifier)

  combined_suite.name = "#{name} + #{other_suite.name}"

  combined_suite
end

#reset_statement_indexObject



68
69
70
# File 'lib/modspec/suite.rb', line 68

def reset_statement_index
  @statement_index = nil
end

#resolve_conflicts(other_suite) ⇒ Object



76
77
78
79
80
81
# File 'lib/modspec/suite.rb', line 76

def resolve_conflicts(other_suite)
  resolve_conflicts_for(normative_statements_classes,
                        other_suite.normative_statements_classes)
  resolve_conflicts_for(conformance_classes,
                        other_suite.conformance_classes)
end

#setup_relationshipsObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/modspec/suite.rb', line 93

def setup_relationships
  return unless normative_statements_classes && conformance_classes

  req_index = normative_statements_classes
    .flat_map(&:normative_statements)
    .to_h { |r| [r.identifier.to_s, r] }

  conformance_classes.each do |cc|
    cc.tests.each do |ct|
      targets = Array(ct.targets).map(&:to_s)
      ct.corresponding_requirements = targets.filter_map do |t|
        req_index[t]
      end
      ct.parent_class = cc
    end
  end
end

#statement_indexObject



64
65
66
# File 'lib/modspec/suite.rb', line 64

def statement_index
  @statement_index ||= build_statement_index
end

#validateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/modspec/suite.rb', line 22

def validate
  setup_relationships
  reset_statement_index
  errors = super
  errors.concat(validate_cycles)
  errors.concat(validate_label_uniqueness)
  errors.concat(validate_dependencies)
  unless normative_statements_classes.nil?
    errors.concat(normative_statements_classes.flat_map(&:validate))
  end
  errors.concat(conformance_classes.flat_map(&:validate)) unless conformance_classes.nil?
  errors
end