Class: Insika::Workflow::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/insika/workflow.rb

Overview

Zero-dependency instance validator for a plain JSON Schema Hash, speaking the same safe subset (object/array/string/number/integer/boolean + enum) the ToolDefinition validates its parameters against. It implements the SAME #call(value) -> result{#success?, #errors} contract as dry-schema, so the Definition treats both uniformly. Not a full JSON Schema engine (no composition/$ref — the subset the insika supports everywhere); permissive on unknown keys (JSON Schema's additionalProperties default).

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_schema) ⇒ Schema

Returns a new instance of Schema.



101
102
103
104
105
106
107
# File 'lib/insika/workflow.rb', line 101

def initialize(json_schema)
  unless json_schema.is_a?(Hash)
    raise Insika::ValidationError, "workflow schema must be a JSON Schema object or a #call-able validator"
  end

  @json_schema = Insika::Coercion.deep_stringify(json_schema)
end

Instance Attribute Details

#json_schemaObject (readonly)

Returns the value of attribute json_schema.



99
100
101
# File 'lib/insika/workflow.rb', line 99

def json_schema
  @json_schema
end

Class Method Details

.coerce(schema) ⇒ Object

nil -> nil; a callable (dry-schema / proc) -> as-is; a JSON Schema Hash -> wrapped. Idempotent for an existing Schema (it is callable).



92
93
94
95
96
97
# File 'lib/insika/workflow.rb', line 92

def self.coerce(schema)
  return nil if schema.nil?
  return schema if schema.respond_to?(:call)

  new(schema)
end

Instance Method Details

#call(value) ⇒ Object



109
110
111
# File 'lib/insika/workflow.rb', line 109

def call(value)
  Result.new(errors: collect(@json_schema, value, "").freeze)
end