Class: JSONSkooma::Keywords::Core::Vocabulary

Inherits:
Base
  • Object
show all
Defined in:
lib/json_skooma/keywords/core/vocabulary.rb

Instance Attribute Summary

Attributes inherited from Base

#json, #parent_schema

Instance Method Summary collapse

Methods inherited from Base

#each_schema, #evaluate, inherited, #instance_types, #key, #resolve, set_defaults, #static, value_schema=

Constructor Details

#initialize(parent_schema, value) ⇒ Vocabulary

Returns a new instance of Vocabulary.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/json_skooma/keywords/core/vocabulary.rb', line 10

def initialize(parent_schema, value)
  super

  return unless parent_schema.is_a?(Metaschema)

  core_vocab_uri = parent_schema.core_vocabulary&.uri.to_s
  if core_vocab_uri.empty? || !value[core_vocab_uri]
    raise Error, "The `$vocabulary` keyword must list the core vocabulary with a value of true"
  end

  value.each do |vocabulary_uri, vocabulary_required|
    uri = URI.parse(vocabulary_uri)

    vocabulary = parent_schema.registry.vocabulary(uri)
    parent_schema.kw_classes.merge!(vocabulary.kw_classes)
  rescue RegistryError
    if vocabulary_required
      raise Error, "The metaschema requires an unrecognized vocabulary #{vocabulary_uri}"
    end
  end
end