Class: Prescient::Agent::SchemaValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/prescient/agent/schema_validator.rb

Overview

Validates the JSON-schema subset used by agent tools. rubocop:disable Metrics/ClassLength

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ SchemaValidator

Returns a new instance of SchemaValidator.



16
17
18
# File 'lib/prescient/agent/schema_validator.rb', line 16

def initialize(schema)
  @schema = schema.is_a?(Hash) ? schema : {}
end

Class Method Details

.validate!(schema, value) ⇒ Object

Validate a value against a schema.

Parameters:

  • schema (Hash)

    Supported JSON-schema subset

  • value (Object)

    Value to validate

Returns:

  • (Object)

    The validated value



12
13
14
# File 'lib/prescient/agent/schema_validator.rb', line 12

def self.validate!(schema, value)
  new(schema).validate!(value)
end

Instance Method Details

#validate!(value) ⇒ Object

Validate a value against this validator's schema.

Parameters:

  • value (Object)

    Value to validate

Returns:

  • (Object)

    The validated value



23
24
25
26
# File 'lib/prescient/agent/schema_validator.rb', line 23

def validate!(value)
  validate_schema(@schema, value, [])
  value
end