lib/modspec/conformance_class.rb in modspec-0.1.0 vs lib/modspec/conformance_class.rb in modspec-0.1.1
- old
+ new
@@ -1,21 +1,23 @@
-require "shale"
-require_relative "./conformance_test"
-require_relative "./identifier"
+# frozen_string_literal: true
-module Modspec
+require "lutaml/model"
+require_relative "conformance_test"
+require_relative "identifier"
- class ConformanceClass < Shale::Mapper
+module Modspec
+ class ConformanceClass < Lutaml::Model::Serializable
attribute :identifier, Identifier
- attribute :name, Shale::Type::String
- attribute :description, Shale::Type::String
- attribute :classification, Shale::Type::String
+ attribute :name, :string
+ attribute :description, :string
+ attribute :guidance, :string, collection: true
+ attribute :classification, :string
attribute :dependencies, Identifier, collection: true
attribute :target, Identifier, collection: true
attribute :tests, ConformanceTest, collection: true
attribute :belongs_to, Identifier, collection: true
- attribute :reference, Shale::Type::String
+ attribute :reference, :string
xml do
root "conformance-class"
map_attribute "identifier", to: :identifier
map_element "name", to: :name
@@ -23,10 +25,37 @@
map_element "target", to: :target
map_element "classification", to: :classification
map_element "tests", to: :tests
map_element "belongs_to", to: :belongs_to
map_element "description", to: :description
+ map_element "guidance", to: :guidance
map_element "reference", to: :reference
end
- end
+ def validate
+ errors = super()
+ errors.concat(validate_identifier_prefix)
+ errors.concat(validate_class_children_mapping)
+ errors.concat(tests.flat_map(&:validate))
+ errors
+ end
+
+ private
+
+ def validate_class_children_mapping
+ if tests.empty?
+ ["Conformance class #{identifier} has no child conformance tests"]
+ else
+ []
+ end
+ end
+
+ def validate_identifier_prefix
+ errors = []
+ expected_prefix = "#{identifier}/"
+ tests.each do |test|
+ errors << "Conformance test #{test.identifier} does not share the expected prefix #{expected_prefix}" unless test.identifier.to_s.start_with?(expected_prefix)
+ end
+ errors
+ end
+ end
end