Class: JSI::MetaSchemaNode::BootstrapSchema Private

Inherits:
Object
  • Object
show all
Includes:
Schema, Schema::SchemaAncestorNode, Util::FingerprintHash::Immutable
Defined in:
lib/jsi/metaschema_node/bootstrap_schema.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

internal class to bootstrap a meta-schema. represents a schema without the complexity of JSI::Base. the schema is represented but schemas describing the schema are not.

this class is to only be instantiated on nodes in the document that are known to be schemas. Schema#subschema and Schema#resource_root_subschema are the intended mechanisms to instantiate subschemas and resolve references. #[] and #jsi_root_node are not implemented.

BootstrapSchema does not support mutation; its document must be immutable.

Constant Summary

Constants included from Schema

Schema::ReferenceError

Instance Attribute Summary collapse

Attributes included from Schema::SchemaAncestorNode

#jsi_base_uri, #jsi_schema_dynamic_anchor_map, #jsi_schema_resource_ancestors

Instance Method Summary collapse

Methods included from Schema

#anchors, #described_object_property_names, #describes_schema!, #describes_schema?, #dialect_invoke_each, #each_child_applicator_schema, #each_immediate_subschema_ptr, #each_inplace_applicator_schema, #each_inplace_child_applicator_schema, ensure_metaschema, ensure_schema, #id, #instance_valid!, #instance_valid?, #instance_validate, #jsi_as_child_default_as_jsi, #jsi_each_descendent_schema, #jsi_each_descendent_schema_same_resource, #jsi_is_resource_root?, #jsi_is_schema?, #jsi_schema_module, #jsi_schema_module_exec, #jsi_schema_module_name, #jsi_schema_module_name_from_ancestor, #jsi_subschema_resource_ancestors, #keyword?, #keyword_value?, #new_jsi, #schema_absolute_uri, #schema_absolute_uris, #schema_content, #schema_ref, #schema_resource_root, #schema_resource_root?, #schema_uri, #schema_uris

Methods included from Schema::SchemaAncestorNode

#jsi_anchor_subschemas, #jsi_is_resource_root?, #jsi_next_base_uri, #jsi_resource_root, #jsi_resource_uri, #jsi_resource_uris, #jsi_schema_base_uri, #jsi_schema_registry

Constructor Details

#initialize(dialect:, jsi_document:, jsi_ptr: Ptr[], jsi_base_uri: nil, jsi_schema_resource_ancestors: Util::EMPTY_ARY, jsi_schema_dynamic_anchor_map: Schema::DynamicAnchorMap::EMPTY, jsi_registry: nil) ⇒ BootstrapSchema

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of BootstrapSchema.

Parameters:

  • jsi_ptr (JSI::Ptr) (defaults to: Ptr[])

    pointer to the schema in the document

  • jsi_document (#to_hash, #to_ary, Boolean, Object)

    document containing the schema



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 22

def initialize(
    dialect: ,
    jsi_document: ,
    jsi_ptr: Ptr[],
    jsi_base_uri: nil,
    jsi_schema_resource_ancestors: Util::EMPTY_ARY,
    jsi_schema_dynamic_anchor_map: Schema::DynamicAnchorMap::EMPTY,
    jsi_registry: nil
)
  @dialect = dialect
  #chkbug fail(Bug) unless jsi_ptr.resolve_against(jsi_document).equal?(jsi_ptr)
  @jsi_ptr = jsi_ptr
  @jsi_document = jsi_document
  self.jsi_base_uri = jsi_base_uri
  self.jsi_schema_resource_ancestors = jsi_schema_resource_ancestors
  self.jsi_schema_dynamic_anchor_map = jsi_schema_dynamic_anchor_map
  @jsi_registry = jsi_registry

  @memos = {}
  @jsi_node_content = jsi_ptr.evaluate(jsi_document)

  super()
end

Instance Attribute Details

#dialectSchema::Dialect (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



47
48
49
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 47

def dialect
  @dialect
end

#jsi_documentObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

document containing the schema content



50
51
52
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 50

def jsi_document
  @jsi_document
end

#jsi_node_contentObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



62
63
64
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 62

def jsi_node_content
  @jsi_node_content
end

#jsi_ptrObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

JSI::Ptr pointing to this schema within the document



53
54
55
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 53

def jsi_ptr
  @jsi_ptr
end

#jsi_registryRegistry? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



60
61
62
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 60

def jsi_registry
  @jsi_registry
end

Instance Method Details

#jsi_fingerprintObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

see Util::Private::FingerprintHash



168
169
170
171
172
173
174
175
176
177
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 168

def jsi_fingerprint
  {
    class: self.class,
    dialect: dialect,
    jsi_ptr: @jsi_ptr,
    jsi_document: @jsi_document,
    jsi_schema_dynamic_anchor_map: jsi_schema_dynamic_anchor_map,
    jsi_registry: jsi_registry,
  }.freeze
end

#jsi_root_urinil

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (nil)


56
57
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 56

def jsi_root_uri
end

#pretty_print(q)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

pretty-prints a representation of self to the given printer



149
150
151
152
153
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 149

def pretty_print(q)
  jsi_pp_object_group(q, jsi_object_group_text) do
      q.pp schema_content
  end
end

#resource_root_subschema(ptr) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

overrides Schema#resource_root_subschema



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 90

def resource_root_subschema(ptr)
  ptr = Ptr.ary_ptr(ptr)
  if jsi_resource_root
    curschema = jsi_resource_root
    remptr = ptr.resolve_against(jsi_resource_root.jsi_node_content)
    found = true
    while found
      return(curschema) if remptr.empty?
      found = false
      curschema.each_immediate_subschema_ptr do |subptr|
        if subptr.ancestor_of?(remptr)
          curschema = curschema.subschema(subptr)
          remptr = remptr.relative_to(subptr)
          found = true
          break
        end
      end
    end
    # ptr indicates a location where no element indicates a subschema.
    # TODO rm support (along with reinstantiate_as) and raise(NotASchemaError) here.
    return(curschema.subschema(remptr))
  end
  # no jsi_resource_root means the root is not a schema and no parent schema has an absolute uri.
  # result schema is instantiated relative to document root.
  dialect.bootstrap_schema(
    jsi_document: jsi_document,
    jsi_ptr: ptr.resolve_against(jsi_document),
    jsi_base_uri: nil,
    jsi_schema_resource_ancestors: Util::EMPTY_ARY,
    jsi_schema_dynamic_anchor_map: jsi_schema_dynamic_anchor_map,
    jsi_registry: jsi_registry,
  )
end

#subschema(subptr) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

overrides Schema#subschema



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 65

def subschema(subptr)
  subptr = Ptr.ary_ptr(subptr).resolve_against(jsi_node_content)
  kw = {
    jsi_document: jsi_document,
    jsi_ptr: jsi_ptr + subptr,
    jsi_base_uri: jsi_next_base_uri,
    jsi_schema_resource_ancestors: jsi_subschema_resource_ancestors,
    jsi_registry: jsi_registry,
  }
  # determine if subschema is a resource root here, for dynamic_anchor_map.
  # done in the same manner as Base#jsi_child_dynamic_anchor_map, when child is a schema - a bootstrap schema is instantiated
  # to check #jsi_is_resource_root?. here, though, that bootstrap schema is usually the returned subschema.
  subschema = dialect.bootstrap_schema(**kw,
    jsi_schema_dynamic_anchor_map: jsi_schema_dynamic_anchor_map,
  )
  if subschema.jsi_is_resource_root?
    # if subschema is a resource root, it should have our jsi_next_schema_dynamic_anchor_map
    subschema = dialect.bootstrap_schema(**kw,
      jsi_schema_dynamic_anchor_map: jsi_next_schema_dynamic_anchor_map.without_node(self, ptr: jsi_ptr + subptr),
    )
  end
  subschema
end