Class: MCPClient::SchemaValidator::Evaluated

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp_client/schema_validator/annotations.rb

Overview

What the schemas applied to one instance value evaluated of it: the annotation results unevaluatedProperties and unevaluatedItems read (JSON Schema 2020-12 Core Sections 11.2 and 11.3). One is kept per application of a schema to an object or an array, filled in by the keywords the node evaluates itself (properties, patternProperties, additionalProperties, prefixItems, items, contains and the two keywords themselves) and merged from every in-place applicator whose subschema passed — a failed subschema annotates nothing, and a cousin (a sibling branch of the same composition) never sees it.

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Evaluated

Returns a new instance of Evaluated.



15
16
17
18
19
20
# File 'lib/mcp_client/schema_validator/annotations.rb', line 15

def initialize
  @all = false
  @names = {}
  @prefix = 0
  @indices = {}
end

Instance Method Details

#all! ⇒ void

This method returns an undefined value.

Every member or item is evaluated (an items schema, an additionalProperties schema, or the unevaluated keyword itself).



30
31
32
# File 'lib/mcp_client/schema_validator/annotations.rb', line 30

def all!
  @all = true
end

#all? ⇒ Boolean

Returns whether every member or item was evaluated.

Returns:

  • (Boolean) —

    whether every member or item was evaluated



23
24
25
# File 'lib/mcp_client/schema_validator/annotations.rb', line 23

def all?
  @all
end

#index!(index) ⇒ void

This method returns an undefined value.

Parameters:

  • index (Integer) —

    an item contains matched



48
49
50
# File 'lib/mcp_client/schema_validator/annotations.rb', line 48

def index!(index)
  @indices[index] = true unless @all
end

#item?(index) ⇒ Boolean

Returns whether the item was evaluated.

Parameters:

  • index (Integer)

Returns:

  • (Boolean) —

    whether the item was evaluated



60
61
62
# File 'lib/mcp_client/schema_validator/annotations.rb', line 60

def item?(index)
  @all || index < @prefix || @indices.key?(index)
end

#merge!(other) ⇒ Evaluated

Take over what a passed subschema evaluated of the same value.

Parameters:

Returns:



67
68
69
70
71
72
73
74
75
# File 'lib/mcp_client/schema_validator/annotations.rb', line 67

def merge!(other)
  return self if other.nil?
  return all! || self if other.all?

  @names.merge!(other.names)
  @prefix = other.prefix if other.prefix > @prefix
  @indices.merge!(other.indices)
  self
end

#name!(name) ⇒ void

This method returns an undefined value.

Parameters:

  • name (Object) —

    a property name (either key form)



36
37
38
# File 'lib/mcp_client/schema_validator/annotations.rb', line 36

def name!(name)
  @names[name.to_s] = true unless @all
end

#prefix!(count) ⇒ void

This method returns an undefined value.

Parameters:

  • count (Integer) —

    how many leading items a tuple evaluated



42
43
44
# File 'lib/mcp_client/schema_validator/annotations.rb', line 42

def prefix!(count)
  @prefix = count if count > @prefix
end

#property?(name) ⇒ Boolean

Returns whether the member was evaluated.

Parameters:

  • name (Object) —

    a property name (either key form)

Returns:

  • (Boolean) —

    whether the member was evaluated



54
55
56
# File 'lib/mcp_client/schema_validator/annotations.rb', line 54

def property?(name)
  @all || @names.key?(name.to_s)
end