Module: Lutaml::Model::Validation

Included in:
Serialize
Defined in:
lib/lutaml/model/validation.rb

Instance Method Summary collapse

Instance Method Details

#validateObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lutaml/model/validation.rb', line 4

def validate
  errors = []
  self.class.attributes.each do |name, attr|
    value = public_send(:"#{name}")
    begin
      if value.respond_to?(:validate)
        errors.concat(value.validate)
      else
        attr.validate_value!(value)
      end
    rescue Lutaml::Model::InvalidValueError,
           Lutaml::Model::CollectionCountOutOfRangeError,
           Lutaml::Model::CollectionTrueMissingError,
           Lutaml::Model::PolymorphicError,
           PatternNotMatchedError => e
      errors << e
    end
  end

  validate_helper(errors)
end

#validate!Object



26
27
28
29
# File 'lib/lutaml/model/validation.rb', line 26

def validate!
  errors = validate
  raise Lutaml::Model::ValidationError.new(errors) if errors.any?
end

#validate_helper(errors) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/lutaml/model/validation.rb', line 31

def validate_helper(errors)
  self.class.choice_attributes.each do |attribute|
    attribute.validate_content!(self)
  end
  errors
rescue Lutaml::Model::ChoiceUpperBoundError,
       Lutaml::Model::ChoiceLowerBoundError => e
  errors << e
end