Sha256: 1fd2e40f304feb70f9b0f86a0df35b7f950460b8ef5f3a6c31d37d13e926fef0

Contents?: true

Size: 762 Bytes

Versions: 12

Compression:

Stored size: 762 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
    include Enumerable

    def initialize
      @schema_map = {}
    end

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

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

    def lookup_schema(uri)
      uri = uri.chomp('#')
      @schema_map[uri]
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
json_schema-0.11.0 lib/json_schema/document_store.rb
json_schema-0.10.0 lib/json_schema/document_store.rb
json_schema-0.9.0 lib/json_schema/document_store.rb
json_schema-0.8.0 lib/json_schema/document_store.rb
json_schema-0.7.1 lib/json_schema/document_store.rb
json_schema-0.7.0 lib/json_schema/document_store.rb
json_schema-0.6.2 lib/json_schema/document_store.rb
json_schema-0.6.1 lib/json_schema/document_store.rb
json_schema-0.6.0 lib/json_schema/document_store.rb
json_schema-0.5.0 lib/json_schema/document_store.rb
json_schema-0.4.0 lib/json_schema/document_store.rb
json_schema-0.3.1 lib/json_schema/document_store.rb