Sha256: 4b0fd1ff2d2c26a8143919968d0c5da8c6312e5499d219f9967d7b8e488c27be

Contents?: true

Size: 679 Bytes

Versions: 3

Compression:

Stored size: 679 Bytes

Contents

module JsonSchema
  # 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.
  class DocumentStore
    def initialize
      @schema_map = {}
    end

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

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

    def lookup_uri(uri)
      @schema_map[uri]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
json_schema-0.0.17 lib/json_schema/document_store.rb
json_schema-0.0.16 lib/json_schema/document_store.rb
json_schema-0.0.15 lib/json_schema/document_store.rb