Exception: Purl::ValidationError

Inherits:
Error
  • Object
show all
Defined in:
lib/purl/errors.rb

Overview

Validation errors for PURL components

Contains additional context about which component failed validation and what rule was violated.

Examples:

begin
  PackageURL.new(type: "123invalid", name: "test")
rescue ValidationError => e
  puts e.component  # :type
  puts e.rule       # "cannot start with number" 
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, component: nil, value: nil, rule: nil) ⇒ ValidationError

Returns a new instance of ValidationError.

Parameters:

  • message (String)

    error message

  • component (Symbol, nil) (defaults to: nil)

    component that failed validation

  • value (Object, nil) (defaults to: nil)

    value that failed validation

  • rule (String, nil) (defaults to: nil)

    validation rule that was violated



33
34
35
36
37
38
# File 'lib/purl/errors.rb', line 33

def initialize(message, component: nil, value: nil, rule: nil)
  super(message)
  @component = component
  @value = value
  @rule = rule
end

Instance Attribute Details

#componentSymbol? (readonly)

Returns the PURL component that failed validation.

Returns:

  • (Symbol, nil)

    the PURL component that failed validation



21
22
23
# File 'lib/purl/errors.rb', line 21

def component
  @component
end

#ruleString? (readonly)

Returns the validation rule that was violated.

Returns:

  • (String, nil)

    the validation rule that was violated



27
28
29
# File 'lib/purl/errors.rb', line 27

def rule
  @rule
end

#valueObject? (readonly)

Returns the value that failed validation.

Returns:

  • (Object, nil)

    the value that failed validation



24
25
26
# File 'lib/purl/errors.rb', line 24

def value
  @value
end