Module: JSI::SchemaModule::Connects

Included in:
JSI::SchemaModule, Connection
Defined in:
lib/jsi/schema_classes.rb

Overview

connecting JSI::SchemaModules via Connections

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#jsi_nodeObject (readonly)

Returns the value of attribute jsi_node.



267
268
269
# File 'lib/jsi/schema_classes.rb', line 267

def jsi_node
  @jsi_node
end

Instance Method Details

#[](token, **kw) { ... } ⇒ SchemaModule, ...

Subscripting a JSI schema module or a JSI::SchemaModule::Connection will subscript its node, and if the result is a JSI::Schema, return the JSI Schema module of that schema; if it is a JSI::Base, return a SchemaModule::Connection; or if it is another value (a basic type), return that value.

Parameters:

  • token (Object)

Yields:

  • If the token identifies a schema and a block is given, it is evaluated in the context of the schema's JSI schema module using Module#module_exec.

Returns:

Raises:

  • (ArgumentError)


302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/jsi/schema_classes.rb', line 302

def [](token, **kw, &block)
  raise(ArgumentError) unless kw.empty? # TODO remove eventually (keyword argument compatibility)
  sub = @jsi_node[token]
  if sub.is_a?(JSI::Schema)
    sub.jsi_schema_module_exec(&block) if block
    sub.jsi_schema_module
  elsif block
    raise(ArgumentError, "block given but token #{token.inspect} does not identify a schema")
  elsif sub.is_a?(JSI::Base)
    SchemaModule::Connection.new(sub)
  else
    sub
  end
end

#name_from_ancestorString?

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.

a name relative to a named schema module of an ancestor schema. for example, if Foos = JSI::JSONSchemaDraft07.new_schema_module({'items' => {}}) then the module Foos.items will have a name_from_ancestor of "Foos.items"

Returns:

  • (String, nil)


274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/jsi/schema_classes.rb', line 274

def name_from_ancestor
  named_ancestor_schema, tokens = named_ancestor_schema_tokens
  return nil unless named_ancestor_schema

  name = named_ancestor_schema.jsi_schema_module.name
  ancestor = named_ancestor_schema
  tokens.each do |token|
    if ancestor.jsi_property_readers.include?(token)
      name += ".#{token}"
    elsif [String, Numeric, TrueClass, FalseClass, NilClass].any? { |m| token.is_a?(m) }
      name += "[#{token.inspect}]"
    else
      return nil
    end
    ancestor = ancestor[token]
  end
  name.freeze
end