Class: JSI::SchemaModule

Inherits:
Module
  • Object
show all
Includes:
Connects
Defined in:
lib/jsi/schema_classes.rb,
lib/jsi/schema_classes.rb

Overview

A Module associated with a JSI Schema. See JSI::Schema#jsi_schema_module.

Defined Under Namespace

Modules: Connects, MetaSchemaModule Classes: Connection

Instance Attribute Summary

Attributes included from Connects

#jsi_node

Instance Method Summary collapse

Methods included from Connects

#[], #name_from_ancestor

Instance Method Details

#inspectString

Returns:

  • (String)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/jsi/schema_classes.rb', line 30

def inspect
  if name_from_ancestor
    if schema.schema_absolute_uri
      -"#{name_from_ancestor} <#{schema.schema_absolute_uri}> (JSI Schema Module)"
    else
      -"#{name_from_ancestor} (JSI Schema Module)"
    end
  else
    -"(JSI Schema Module: #{schema.schema_uri || schema.jsi_ptr.uri})"
  end
end

#instance_valid?(instance) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/jsi/schema_classes.rb', line 66

def instance_valid?(instance)
  schema.instance_valid?(instance)
end

#instance_validate(instance) ⇒ Object



61
62
63
# File 'lib/jsi/schema_classes.rb', line 61

def instance_validate(instance)
  schema.instance_validate(instance)
end

#new_jsi(instance, **kw) ⇒ JSI::Base subclass

invokes JSI::Schema#new_jsi on this module's schema, passing the given parameters.

Parameters:

  • instance (Object)

    the instance to be represented as a JSI

  • uri (#to_str, Addressable::URI)

    The retrieval URI of the instance.

    It is rare that this needs to be specified, and only useful for instances which contain schemas. See JSI::Schema::MetaSchema#new_schema's uri param documentation.

  • register (Boolean)

    Whether schema resources in the instantiated JSI will be registered in the schema registry indicated by param schema_registry. This is only useful when the JSI is a schema or contains schemas. The JSI's root will be registered with the uri param, if specified, whether or not the root is a schema.

  • schema_registry (SchemaRegistry, nil)

    The registry to use for references to other schemas and, depending on register and uri params, to register this JSI and/or any contained schemas with declared URIs.

  • stringify_symbol_keys (Boolean)

    Whether the instance content will have any Symbol keys of Hashes replaced with Strings (recursively through the document). Replacement is done on a copy; the given instance is not modified.

  • to_immutable (#call, nil)

    A proc/callable which takes given instance content and results in an immutable (i.e. deeply frozen) object equal to that. If the instantiated JSI will be mutable, this is not used. Though not recommended, this may be nil with immutable JSIs if the instance content is otherwise guaranteed to be immutable, as well as any modified copies of the instance.

  • mutable (Boolean)

    Whether the instantiated JSI will be mutable. The instance content will be transformed with to_immutable if the JSI will be immutable.

Returns:

  • (JSI::Base subclass)

    a JSI whose content comes from the given instance and whose schemas are inplace applicators of this module's schema.



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

def new_jsi(instance, **kw)
  schema.new_jsi(instance, **kw)
end

#schemaBase + Schema

The schema for which this is the JSI Schema Module

Returns:



19
20
21
# File 'lib/jsi/schema_classes.rb', line 19

def schema
  @jsi_node
end

#schema_contentObject



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

def schema_content
  schema.jsi_node_content
end

#schema_uriAddressable::URI?

a URI which refers to the schema. see JSI::Schema#schema_uri.

Returns:

  • (Addressable::URI, nil)


25
26
27
# File 'lib/jsi/schema_classes.rb', line 25

def schema_uri
  schema.schema_uri
end

#to_sObject



42
43
44
# File 'lib/jsi/schema_classes.rb', line 42

def to_s
  inspect
end