Class: Schemurai::SchemaRegistry
- Inherits:
-
Object
- Object
- Schemurai::SchemaRegistry
- Defined in:
- lib/schemurai.rb
Instance Method Summary collapse
- #compile(schema, base_uri: nil, content: false, format: false) ⇒ Object
-
#initialize(schemas: {}) ⇒ SchemaRegistry
constructor
A new instance of SchemaRegistry.
- #make_shareable ⇒ Object
- #shareable? ⇒ Boolean
- #validator_for(uri, content: false, format: false) ⇒ Object
Constructor Details
#initialize(schemas: {}) ⇒ SchemaRegistry
Returns a new instance of SchemaRegistry.
34 35 36 37 |
# File 'lib/schemurai.rb', line 34 def initialize(schemas: {}) @graph = Internal::SchemaGraph.new(schemas: schemas) @shareable = false end |
Instance Method Details
#compile(schema, base_uri: nil, content: false, format: false) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/schemurai.rb', line 39 def compile(schema, base_uri: nil, content: false, format: false) raise Error, "cannot compile schemas after the registry is made shareable" if @shareable root = @graph.compile(schema, base_uri: base_uri) Validator.new(@graph, root, content: content, format: format) end |
#make_shareable ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/schemurai.rb', line 46 def make_shareable return self if @shareable @graph.make_shareable @shareable = true Ractor.make_shareable(self) end |
#shareable? ⇒ Boolean
54 55 56 |
# File 'lib/schemurai.rb', line 54 def shareable? @shareable end |
#validator_for(uri, content: false, format: false) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/schemurai.rb', line 58 def validator_for(uri, content: false, format: false) raise Error, "make_shareable must be called before retrieving validators by URI" unless @shareable root = @graph.node_at(uri) raise ResolutionError, "unregistered schema URI #{uri.inspect}" unless root Validator.new(@graph, root, content: content, format: format) end |