Class: RubyLLM::Contract::SchemaValidator::BoundRule

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/contract/contract/schema_validator/bound_rule.rb

Overview

Validates numeric and collection size bounds for a node.

Constant Summary collapse

NUMERIC_LIMITS =
[
  { key: :minimum, label: "minimum", relation: "below", invalid: ->(actual, limit) { actual < limit } },
  { key: :maximum, label: "maximum", relation: "above", invalid: ->(actual, limit) { actual > limit } }
].freeze
SIZE_LIMITS =
[
  { bound: :min_key, relation: "below", invalid: ->(actual, limit) { actual < limit } },
  { bound: :max_key, relation: "above", invalid: ->(actual, limit) { actual > limit } }
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(errors) ⇒ BoundRule

Returns a new instance of BoundRule.



17
18
19
# File 'lib/ruby_llm/contract/contract/schema_validator/bound_rule.rb', line 17

def initialize(errors)
  @errors = errors
end

Instance Method Details

#validate(node) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/ruby_llm/contract/contract/schema_validator/bound_rule.rb', line 21

def validate(node)
  value = node.value
  schema = node.schema
  path = node.path

  append_numeric_bound_errors(path, value, schema) if value.is_a?(Numeric)
  append_size_bound_errors(path, value, schema)
end