class JsonSchema::DocumentStore
The document store helps resolve URI-based JSON pointers by storing IDs that we've seen in the schema.
Each URI tuple also contains a pointer map that helps speed up expansions that have already happened and handles cyclic dependencies. Store a reference to the top-level schema before doing anything else.
Public Class Methods
new()
click to toggle source
# File lib/json_schema/document_store.rb, line 11 def initialize @schema_map = {} end
Public Instance Methods
add_schema(schema)
click to toggle source
# File lib/json_schema/document_store.rb, line 15 def add_schema(schema) raise ArgumentError, "can't add nil URI" if schema.uri.nil? uri = schema.uri.chomp('#') @schema_map[uri] = schema end
each() { |k, v| ... }
click to toggle source
# File lib/json_schema/document_store.rb, line 21 def each @schema_map.each { |k, v| yield(k, v) } end
lookup_schema(uri)
click to toggle source
# File lib/json_schema/document_store.rb, line 25 def lookup_schema(uri) uri = uri.chomp('#') @schema_map[uri] end