Class: Ukiryu::Definition::ValidationResult
- Inherits:
-
Object
- Object
- Ukiryu::Definition::ValidationResult
- Defined in:
- lib/ukiryu/definition/validation_result.rb
Overview
Result of a definition validation
This class represents the result of validating a tool definition against a JSON Schema or other validation rules.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#schema_path ⇒ Object
readonly
Returns the value of attribute schema_path.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
-
.failure(errors, warnings = []) ⇒ ValidationResult
Create a failed validation result.
-
.success ⇒ ValidationResult
Create a successful validation result.
-
.with_warnings(warnings) ⇒ ValidationResult
Create a result with warnings.
Instance Method Summary collapse
-
#error_count ⇒ Integer
Get error count.
-
#has_errors? ⇒ Boolean
Check if there are any errors.
-
#has_warnings? ⇒ Boolean
Check if there are any warnings.
-
#initialize(valid:, errors: [], warnings: [], schema_path: nil) ⇒ ValidationResult
constructor
A new instance of ValidationResult.
-
#invalid? ⇒ Boolean
Check if validation failed.
-
#issue_count ⇒ Integer
Get total issue count.
-
#summary ⇒ String
Human-readable summary.
-
#to_h ⇒ Hash
Convert to hash.
-
#to_json(*args) ⇒ String
Convert to JSON.
-
#to_s ⇒ String
Detailed message string.
-
#valid? ⇒ Boolean
Check if validation passed.
-
#warning_count ⇒ Integer
Get warning count.
Constructor Details
#initialize(valid:, errors: [], warnings: [], schema_path: nil) ⇒ ValidationResult
Returns a new instance of ValidationResult.
12 13 14 15 16 17 |
# File 'lib/ukiryu/definition/validation_result.rb', line 12 def initialize(valid:, errors: [], warnings: [], schema_path: nil) @valid = valid @errors = errors @warnings = warnings @schema_path = schema_path end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
10 11 12 |
# File 'lib/ukiryu/definition/validation_result.rb', line 10 def errors @errors end |
#schema_path ⇒ Object (readonly)
Returns the value of attribute schema_path.
10 11 12 |
# File 'lib/ukiryu/definition/validation_result.rb', line 10 def schema_path @schema_path end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
10 11 12 |
# File 'lib/ukiryu/definition/validation_result.rb', line 10 def warnings @warnings end |
Class Method Details
.failure(errors, warnings = []) ⇒ ValidationResult
Create a failed validation result
80 81 82 |
# File 'lib/ukiryu/definition/validation_result.rb', line 80 def self.failure(errors, warnings = []) new(valid: false, errors: errors, warnings: warnings) end |
.success ⇒ ValidationResult
Create a successful validation result
71 72 73 |
# File 'lib/ukiryu/definition/validation_result.rb', line 71 def self.success new(valid: true) end |
.with_warnings(warnings) ⇒ ValidationResult
Create a result with warnings
88 89 90 |
# File 'lib/ukiryu/definition/validation_result.rb', line 88 def self.with_warnings(warnings) new(valid: true, warnings: warnings) end |
Instance Method Details
#error_count ⇒ Integer
Get error count
57 58 59 |
# File 'lib/ukiryu/definition/validation_result.rb', line 57 def error_count @errors.length end |
#has_errors? ⇒ Boolean
Check if there are any errors
36 37 38 |
# File 'lib/ukiryu/definition/validation_result.rb', line 36 def has_errors? !@errors.empty? end |
#has_warnings? ⇒ Boolean
Check if there are any warnings
43 44 45 |
# File 'lib/ukiryu/definition/validation_result.rb', line 43 def has_warnings? !@warnings.empty? end |
#invalid? ⇒ Boolean
Check if validation failed
29 30 31 |
# File 'lib/ukiryu/definition/validation_result.rb', line 29 def invalid? !@valid end |
#issue_count ⇒ Integer
Get total issue count
50 51 52 |
# File 'lib/ukiryu/definition/validation_result.rb', line 50 def issue_count @errors.length + @warnings.length end |
#summary ⇒ String
Human-readable summary
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/ukiryu/definition/validation_result.rb', line 117 def summary if valid? if has_warnings? "Valid with #{warning_count} warning(s)" else 'Valid' end else msg = "Invalid (#{error_count} error(s)" msg += ", #{warning_count} warning(s)" if has_warnings? "#{msg})" end end |
#to_h ⇒ Hash
Convert to hash
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ukiryu/definition/validation_result.rb', line 95 def to_h { valid: @valid, errors: @errors, warnings: @warnings, schema_path: @schema_path, error_count: error_count, warning_count: warning_count } end |
#to_json(*args) ⇒ String
Convert to JSON
109 110 111 112 |
# File 'lib/ukiryu/definition/validation_result.rb', line 109 def to_json(*args) require 'json' to_h.to_json(*args) end |
#to_s ⇒ String
Detailed message string
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/ukiryu/definition/validation_result.rb', line 134 def to_s output = [] output << "Validation: #{summary}" if has_errors? output << '' output << 'Errors:' @errors.each_with_index do |error, i| output << " #{i + 1}. #{error}" end end if has_warnings? output << '' output << 'Warnings:' @warnings.each_with_index do |warning, i| output << " #{i + 1}. #{warning}" end end output.join("\n") end |
#valid? ⇒ Boolean
Check if validation passed
22 23 24 |
# File 'lib/ukiryu/definition/validation_result.rb', line 22 def valid? @valid end |
#warning_count ⇒ Integer
Get warning count
64 65 66 |
# File 'lib/ukiryu/definition/validation_result.rb', line 64 def warning_count @warnings.length end |