Class: JSI::MetaschemaNode::BootstrapSchema Private

Inherits:
Object
  • Object
show all
Includes:
Schema, Schema::SchemaAncestorNode, Util::FingerprintHash
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 metaschema. 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.

schema implementation modules are included on generated subclasses of BootstrapSchema by SchemaClasses.bootstrap_schema_class. that subclass is instantiated with a document and pointer, representing a schema.

Instance Attribute Summary collapse

Attributes included from Schema::SchemaAncestorNode

#jsi_schema_base_uri, #jsi_schema_registry, #jsi_schema_resource_ancestors

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Schema

#child_applicator_schemas, #described_object_property_names, #describes_schema!, #describes_schema?, #each_child_applicator_schema, #each_inplace_applicator_schema, #each_schema_uri, ensure_describes_schema, ensure_schema, #inplace_applicator_schemas, #instance_valid?, #instance_validate, #jsi_schema_module, #jsi_schema_module_exec, #jsi_subschema_resource_ancestors, #keyword?, #new_jsi, #schema_absolute_uri, #schema_content, #schema_ref, #schema_resource_root, #schema_resource_root?, #schema_uri, #schema_uris

Methods included from Schema::SchemaAncestorNode

#jsi_anchor_subschema, #jsi_anchor_subschemas, #jsi_resource_ancestor_uri

Constructor Details

#initialize(jsi_document, jsi_ptr: Ptr[], jsi_schema_base_uri: 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

Raises:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 35

def initialize(
    jsi_document,
    jsi_ptr: Ptr[],
    jsi_schema_base_uri: nil
)
  raise(Bug, "no #schema_implementation_modules") unless respond_to?(:schema_implementation_modules)

  super()

  self.jsi_ptr = jsi_ptr
  self.jsi_document = jsi_document
  self.jsi_schema_base_uri = jsi_schema_base_uri
  self.jsi_schema_resource_ancestors = Util::EMPTY_ARY
end

Instance Attribute Details

#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



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

def jsi_document
  @jsi_document
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



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

def jsi_ptr
  @jsi_ptr
end

Class Method Details

.inspectObject

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.



22
23
24
25
26
27
28
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 22

def inspect
  if self == MetaschemaNode::BootstrapSchema
    name
  else
    -"#{name || MetaschemaNode::BootstrapSchema.name} (#{schema_implementation_modules.map(&:inspect).join(', ')})"
  end
end

.to_sObject

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.



30
31
32
33
34
35
36
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 30

def inspect
  if self == MetaschemaNode::BootstrapSchema
    name
  else
    -"#{name || MetaschemaNode::BootstrapSchema.name} (#{schema_implementation_modules.map(&:inspect).join(', ')})"
  end
end

Instance Method Details

#inspectString Also known as: to_s

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:

  • (String)


83
84
85
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 83

def inspect
  -"\#<#{jsi_object_group_text.join(' ')} #{schema_content.inspect}>"
end

#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



116
117
118
119
120
121
122
123
124
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 116

def jsi_fingerprint
  {
    class: self.class,
    jsi_ptr: @jsi_ptr,
    jsi_document: @jsi_document,
    jsi_schema_base_uri: jsi_schema_base_uri,
    schema_implementation_modules: schema_implementation_modules,
  }
end

#jsi_node_contentObject

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.



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

def jsi_node_content
  jsi_ptr.evaluate(jsi_document)
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



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 91

def pretty_print(q)
  q.text '#<'
  q.text jsi_object_group_text.join(' ')
  q.group_sub {
    q.nest(2) {
      q.breakable ' '
      q.pp schema_content
    }
  }
  q.breakable ''
  q.text '>'
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



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 70

def resource_root_subschema(ptr)
  # BootstrapSchema does not track jsi_schema_resource_ancestors used by Schema#schema_resource_root;
  # resource_root_subschema is always relative to the document root.
  # BootstrapSchema also does not implement jsi_root_node or #[]. we instantiate the ptr directly
  # rather than as a subschema from the root.
  self.class.new(
    jsi_document,
    jsi_ptr: Ptr.ary_ptr(ptr),
    jsi_schema_base_uri: nil,
  )
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



61
62
63
64
65
66
67
# File 'lib/jsi/metaschema_node/bootstrap_schema.rb', line 61

def subschema(subptr)
  self.class.new(
    jsi_document,
    jsi_ptr: jsi_ptr + subptr,
    jsi_schema_base_uri: jsi_resource_ancestor_uri,
  )
end