Class: Jsii::Object

Inherits:
Object
  • Object
show all
Extended by:
FqnExtension, Registry, StaticConstants
Includes:
DynamicInvocation, KernelForwarding, Overrides
Defined in:
jsii/object.rb,
jsii/object/registry.rb,
jsii/object/overrides.rb,
jsii/object/kernel_forwarding.rb,
jsii/object/dynamic_invocation.rb

Overview

Base class for all Ruby proxy classes that map to JSII-managed objects.

Defined Under Namespace

Modules: DynamicInvocation, KernelForwarding, Overrides, Registry

Constant Summary

Constants included from Registry

Registry::MONITOR

Instance Attribute Summary collapse

Attributes included from FqnExtension

#jsii_fqn

Instance Method Summary collapse

Methods included from Registry

autoload_paths, find_by_ref, find_class_by_fqn, from_jsii_ref, jsii_deserialize, jsii_fqn, objects, register_autoload, register_instance, register_jsii_fqn, registered_class?, registered_class_counts, registry

Methods included from StaticConstants

const_missing

Methods included from DynamicInvocation

#method_missing, #respond_to_missing?

Methods included from Overrides

#jsii_overrides

Methods included from KernelForwarding

#jsii_async_call_method, #jsii_call_method, #jsii_get_property, #jsii_set_property

Constructor Details

#initialize(*args) {|instance| ... } ⇒ Jsii::Object

Allocate the corresponding object inside the JSII sidecar and store its ref locally. Subclasses do NOT typically override this — the pacmak generator emits a thin initialize(arg1, arg2, ...) that forwards via super, ultimately landing here.

Parameters:

  • args (Array)

    positional constructor arguments (Ruby values).

Yield Parameters:

  • instance (Jsii::Object)

    the freshly-constructed instance, for caller post-init.

Raises:



50
51
52
53
54
55
56
57
58
59
# File 'jsii/object.rb', line 50

def initialize(*args)
  # Ask the singleton to create the remote object and store its reference ID
  @jsii_ref = Jsii::Kernel.instance.create_object(ruby_class.jsii_fqn,
                                                  args,
                                                  overrides: jsii_overrides,
                                                  interfaces: jsii_interfaces,
                                                  instance: self)
  ruby_class.register_instance(self)
  yield self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Jsii::Object::DynamicInvocation

Instance Attribute Details

#jsii_refString (readonly)

Returns the $jsii.byref handle for this proxied instance.

Returns:

  • (String)

    the $jsii.byref handle for this proxied instance.



28
29
30
# File 'jsii/object.rb', line 28

def jsii_ref
  @jsii_ref
end

Instance Method Details

#jsii_interfacesArray<String>

The set of JSII interface FQNs this Ruby instance is declared to implement, gathered from every module in its ancestor chain that carries a jsii_fqn.

Returns:

  • (Array<String>)

    de-duplicated list of interface FQNs.



66
67
68
69
70
71
72
# File 'jsii/object.rb', line 66

def jsii_interfaces
  # Find all included modules that have a jsii_fqn
  singleton_class.ancestors
            .select { |a| a.is_a?(Module) && !a.is_a?(Class) && a.respond_to?(:jsii_fqn) && a.jsii_fqn }
            .map(&:jsii_fqn)
            .uniq
end

#jsii_serializeHash{String=>Object}

Encodes this proxy as a $jsii.byref wire envelope.

Returns:

  • (Hash{String=>Object})

    { "$jsii.byref" => "<handle>", "$jsii.interfaces" => [...] }.



33
34
35
36
37
38
39
# File 'jsii/object.rb', line 33

def jsii_serialize
  res = { '$jsii.byref' => jsii_ref }
  if (interfaces = jsii_interfaces) && !interfaces.empty?
    res['$jsii.interfaces'] = interfaces
  end
  res
end

#ruby_classClass

Returns the true class of self, bypassing any user-defined #class override (the JSII method-missing path otherwise dispatches class over the wire when a remote member happens to be named class).

Returns:

  • (Class)

    the real Ruby class of this instance.



79
80
81
# File 'jsii/object.rb', line 79

def ruby_class
  ::Object.instance_method(:class).bind(self).call
end