Class: JsonSchema::DocumentStore
- Inherits:
-
Object
- Object
- JsonSchema::DocumentStore
- 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
- #add_uri_reference(uri, schema) ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ DocumentStore
constructor
A new instance of DocumentStore.
- #lookup_uri(uri) ⇒ Object
Constructor Details
#initialize ⇒ DocumentStore
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 |
#each ⇒ Object
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 |