Class: JsonSchema::DocumentStore

Inherits:
Object
  • Object
show all
Defined in:
lib/json_schema/document_store.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initializeDocumentStore

Returns a new instance of DocumentStore.



9
10
11
# File 'lib/json_schema/document_store.rb', line 9

def initialize
  @schema_map = {}
end

Instance Method Details

#add_uri_reference(uri, schema) ⇒ Object



13
14
15
16
# File 'lib/json_schema/document_store.rb', line 13

def add_uri_reference(uri, schema)
  raise "can't add nil URI" if uri.nil?
  @schema_map[uri] = schema
end

#eachObject



18
19
20
# File 'lib/json_schema/document_store.rb', line 18

def each
  @schema_map.each { |k, v| yield(k, v) }
end

#lookup_uri(uri) ⇒ Object



22
23
24
# File 'lib/json_schema/document_store.rb', line 22

def lookup_uri(uri)
  @schema_map[uri]
end