Class: Ukiryu::Models::ValidationResult

Inherits:
Object
  • Object
show all
Defined in:
lib/ukiryu/models/validation_result.rb

Overview

Result of validating a tool profile against the schema

Contains validation status and any errors found during validation.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool_name:, valid:, errors: []) ⇒ ValidationResult

Create a new validation result

Parameters:

  • tool_name (String)

    the tool name that was validated

  • valid (Boolean)

    whether validation passed

  • errors (Array<String>) (defaults to: [])

    list of validation errors



16
17
18
19
20
# File 'lib/ukiryu/models/validation_result.rb', line 16

def initialize(tool_name:, valid:, errors: [])
  @tool_name = tool_name
  @valid = valid
  @errors = errors
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/ukiryu/models/validation_result.rb', line 9

def errors
  @errors
end

#tool_nameObject (readonly)

Returns the value of attribute tool_name.



9
10
11
# File 'lib/ukiryu/models/validation_result.rb', line 9

def tool_name
  @tool_name
end

#validObject (readonly)

Returns the value of attribute valid.



9
10
11
# File 'lib/ukiryu/models/validation_result.rb', line 9

def valid
  @valid
end

Class Method Details

.invalid(tool_name, errors) ⇒ ValidationResult

Create an invalid result with errors

Parameters:

  • tool_name (String)

    the tool name

  • errors (Array<String>)

    list of validation errors

Returns:



35
36
37
# File 'lib/ukiryu/models/validation_result.rb', line 35

def self.invalid(tool_name, errors)
  new(tool_name: tool_name, valid: false, errors: errors)
end

.not_found(tool_name) ⇒ ValidationResult

Create a result for a tool not found

Parameters:

  • tool_name (String)

    the tool name

Returns:



43
44
45
# File 'lib/ukiryu/models/validation_result.rb', line 43

def self.not_found(tool_name)
  new(tool_name: tool_name, valid: false, errors: ['Tool not found'])
end

.valid(tool_name) ⇒ ValidationResult

Create a valid result (no errors)

Parameters:

  • tool_name (String)

    the tool name

Returns:



26
27
28
# File 'lib/ukiryu/models/validation_result.rb', line 26

def self.valid(tool_name)
  new(tool_name: tool_name, valid: true, errors: [])
end

Instance Method Details

#invalid?Boolean

Check if validation failed

Returns:

  • (Boolean)

    true if invalid



68
69
70
# File 'lib/ukiryu/models/validation_result.rb', line 68

def invalid?
  !@valid
end

#not_found?Boolean

Check if tool was not found

Returns:

  • (Boolean)

    true if tool not found



75
76
77
# File 'lib/ukiryu/models/validation_result.rb', line 75

def not_found?
  @errors == ['Tool not found']
end

#status_messageString

Get a human-readable status message

Returns:

  • (String)

    status message



50
51
52
53
54
55
56
# File 'lib/ukiryu/models/validation_result.rb', line 50

def status_message
  if valid?
    '✓ Valid'
  else
    "✗ Invalid (#{errors.size} error#{errors.size == 1 ? '' : 's'})"
  end
end

#valid?Boolean

Check if validation passed

Returns:

  • (Boolean)

    true if valid



61
62
63
# File 'lib/ukiryu/models/validation_result.rb', line 61

def valid?
  @valid
end