Class: JsonSchema::DocumentStore
- Inherits:
-
Object
- Object
- JsonSchema::DocumentStore
- Includes:
- Enumerable
- 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_schema(schema) ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ DocumentStore
constructor
A new instance of DocumentStore.
- #lookup_schema(uri) ⇒ Object
Constructor Details
#initialize ⇒ DocumentStore
Returns a new instance of DocumentStore.
11 12 13 |
# File 'lib/json_schema/document_store.rb', line 11 def initialize @schema_map = {} end |
Instance Method Details
#add_schema(schema) ⇒ Object
15 16 17 18 19 |
# File 'lib/json_schema/document_store.rb', line 15 def add_schema(schema) raise "can't add nil URI" if schema.uri.nil? uri = schema.uri.chomp('#') @schema_map[uri] = schema end |
#each ⇒ Object
21 22 23 |
# File 'lib/json_schema/document_store.rb', line 21 def each @schema_map.each { |k, v| yield(k, v) } end |
#lookup_schema(uri) ⇒ Object
25 26 27 28 |
# File 'lib/json_schema/document_store.rb', line 25 def lookup_schema(uri) uri = uri.chomp('#') @schema_map[uri] end |