Class: Lutaml::Model::ValidationContext

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/model/collection.rb

Overview

Internal context class for validation chaining. Allows validations to communicate state and share results. This is an internal API - its interface may change.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeValidationContext

Returns a new instance of ValidationContext.



9
10
11
12
13
# File 'lib/lutaml/model/collection.rb', line 9

def initialize
  @errors = []
  @stopped = false
  @metadata = {}
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/lutaml/model/collection.rb', line 7

def errors
  @errors
end

#metadataObject (readonly)

Returns the value of attribute metadata.



7
8
9
# File 'lib/lutaml/model/collection.rb', line 7

def 
  @metadata
end

Instance Method Details

#[](key) ⇒ Object

Store metadata that can be accessed by subsequent validations

Parameters:

  • key (Symbol)

    The key to store

  • value (Object)

    The value to store



28
29
30
# File 'lib/lutaml/model/collection.rb', line 28

def [](key)
  @metadata[key]
end

#[]=(key, value) ⇒ Object

Retrieve metadata stored by previous validations

Parameters:

  • key (Symbol)

    The key to retrieve

  • value (Object)

    The value to store



35
36
37
# File 'lib/lutaml/model/collection.rb', line 35

def []=(key, value)
  @metadata[key] = value
end

#add_errors(error_list) ⇒ Object

Record that this context received errors

Parameters:

  • error_list (Array)

    List of error messages



46
47
48
# File 'lib/lutaml/model/collection.rb', line 46

def add_errors(error_list)
  @errors.concat(error_list)
end

#failed?Boolean

Check if any validation has added errors

Returns:

  • (Boolean)


40
41
42
# File 'lib/lutaml/model/collection.rb', line 40

def failed?
  @errors.any?
end

#stop!Object

Stop the validation chain - subsequent validations will not run



21
22
23
# File 'lib/lutaml/model/collection.rb', line 21

def stop!
  @stopped = true
end

#stopped?Boolean

Check if the validation chain has been stopped

Returns:

  • (Boolean)


16
17
18
# File 'lib/lutaml/model/collection.rb', line 16

def stopped?
  @stopped
end