Class: Lutaml::Xml::Schema::Xsd::ValidationResult
- Inherits:
-
Model::Serializable
- Object
- Model::Serializable
- Lutaml::Xml::Schema::Xsd::ValidationResult
- Defined in:
- lib/lutaml/xml/schema/xsd/validation_result.rb
Overview
Result of validation with error collection
Constant Summary
Constants included from Model::Serialize
Model::Serialize::DEFAULT_VALUE_MAP, Model::Serialize::INTERNAL_ATTRIBUTES, Model::Serialize::LAZY_EMPTY_COLLECTION
Instance Attribute Summary
Attributes included from Model::Serialize
#lutaml_parent, #lutaml_register, #lutaml_root
Class Method Summary collapse
-
.failure(errors) ⇒ ValidationResult
Create failure result with errors.
-
.success ⇒ ValidationResult
Create success result.
Instance Method Summary collapse
-
#error_count ⇒ Integer
Get error count.
-
#error_messages ⇒ Array<String>
Get all error messages.
-
#errors_for(field) ⇒ Array<ValidationError>
Get errors for specific field.
-
#invalid? ⇒ Boolean
Check if validation failed.
-
#to_s ⇒ String
Format as human-readable string.
-
#valid? ⇒ Boolean
Check if validation passed.
-
#validate! ⇒ Object
Raise error if validation failed.
Methods included from Model::Serialize
#attr_value, #attribute_exist?, #extract_register_id, included, #init_deserialization_state, #initialize, #key_exist?, #key_value, #method_missing, #prepare_instance_format_options, #pretty_print_instance_variables, register_format_mapping_method, register_from_format_method, register_to_format_method, #respond_to_missing?, #to_format, #to_yaml_hash, #using_default?, #using_default_for, #validate_attribute!, #validate_root_mapping!, #value_map, #value_set_for
Methods included from Model::Liquefiable
Methods included from Model::Validation
#format_element_sequences, #order_names, #validate, #validate_helper, #validate_sequence!
Methods included from Model::ComparableModel
#already_compared?, #attributes_hash, #calculate_hash, #comparison_key, #eql?, #hash, included, #same_class?
Methods included from Model::Serialize::Builder
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Lutaml::Model::Serialize
Class Method Details
.failure(errors) ⇒ ValidationResult
Create failure result with errors
29 30 31 |
# File 'lib/lutaml/xml/schema/xsd/validation_result.rb', line 29 def self.failure(errors) new(valid: false, errors: errors) end |
.success ⇒ ValidationResult
Create success result
22 23 24 |
# File 'lib/lutaml/xml/schema/xsd/validation_result.rb', line 22 def self.success new(valid: true, errors: []) end |
Instance Method Details
#error_count ⇒ Integer
Get error count
47 48 49 |
# File 'lib/lutaml/xml/schema/xsd/validation_result.rb', line 47 def error_count (errors || []).size end |
#error_messages ⇒ Array<String>
Get all error messages
53 54 55 |
# File 'lib/lutaml/xml/schema/xsd/validation_result.rb', line 53 def (errors || []).map(&:message) end |
#errors_for(field) ⇒ Array<ValidationError>
Get errors for specific field
60 61 62 63 |
# File 'lib/lutaml/xml/schema/xsd/validation_result.rb', line 60 def errors_for(field) field_str = field.to_s (errors || []).select { |e| e.field == field_str } end |
#invalid? ⇒ Boolean
Check if validation failed
41 42 43 |
# File 'lib/lutaml/xml/schema/xsd/validation_result.rb', line 41 def invalid? !valid end |
#to_s ⇒ String
Format as human-readable string
67 68 69 70 71 72 73 74 75 |
# File 'lib/lutaml/xml/schema/xsd/validation_result.rb', line 67 def to_s return "Valid" if valid? lines = ["Validation failed with #{error_count} error(s):"] errors.each_with_index do |error, idx| lines << " #{idx + 1}. #{error}" end lines.join("\n") end |
#valid? ⇒ Boolean
Check if validation passed
35 36 37 |
# File 'lib/lutaml/xml/schema/xsd/validation_result.rb', line 35 def valid? valid end |
#validate! ⇒ Object
Raise error if validation failed
79 80 81 |
# File 'lib/lutaml/xml/schema/xsd/validation_result.rb', line 79 def validate! raise ValidationFailedError.new(self) if invalid? end |