Module: Jsii::Kernel::Api
- Included in:
- Jsii::Kernel
- Defined in:
- jsii/kernel/api.rb
Overview
Core public APIs exposed by the Kernel to interact with JSII
Instance Method Summary collapse
-
#call_method(objref, method, args = []) ⇒ Object
Invoke an instance method on a previously-created JSII object.
-
#call_static(fqn, method, args = []) ⇒ Object
Invoke a static method on a JSII class.
-
#create_object(fqn, args = [], overrides: [], interfaces: [], instance: nil) ⇒ String
Instantiate a JSII object in the sidecar and return its by-reference id.
-
#get_property(objref, property) ⇒ Object
Read an instance property on a JSII object.
-
#get_static(fqn, property) ⇒ Object
Read a static property on a JSII class.
-
#load_assembly(name, version, tarball) ⇒ Hash
Tell the sidecar to load a JSII assembly from a tarball.
-
#set_property(objref, property, value) ⇒ Hash
Write an instance property on a JSII object.
-
#set_static(fqn, property, value) ⇒ Hash
Write a static property on a JSII class.
Instance Method Details
#call_method(objref, method, args = []) ⇒ Object
Invoke an instance method on a previously-created JSII object.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'jsii/kernel/api.rb', line 55 def call_method(objref, method, args = []) objref_payload = if objref.respond_to?(:jsii_serialize) objref.jsii_serialize else { '$jsii.byref' => objref } end response = request({ api: 'invoke', objref: objref_payload, method: method, args: Jsii::Serializer.dump(args) }) # Unpack the actual returned value Jsii::Serializer.load(response['result']) end |
#call_static(fqn, method, args = []) ⇒ Object
Invoke a static method on a JSII class.
120 121 122 123 124 125 126 127 128 |
# File 'jsii/kernel/api.rb', line 120 def call_static(fqn, method, args = []) response = request({ api: 'sinvoke', fqn: fqn, method: method, args: Jsii::Serializer.dump(args) }) Jsii::Serializer.load(response['result']) end |
#create_object(fqn, args = [], overrides: [], interfaces: [], instance: nil) ⇒ String
Instantiate a JSII object in the sidecar and return its by-reference id.
The instance: argument (if provided) is pushed — together with the
fqn the request is issued with — onto the per-thread pending-object
stack for the duration of the call so that callbacks the kernel fires
during construction can resolve back to the Ruby instance even
though the registry hasn't seen the new ref yet (the fqn lets
find_by_ref reject unknown refs of unrelated types).
37 38 39 40 41 42 43 44 45 46 47 |
# File 'jsii/kernel/api.rb', line 37 def create_object(fqn, args = [], overrides: [], interfaces: [], instance: nil) push_pending_object(instance, fqn) begin payload = create_object_payload(fqn, args, overrides: overrides, interfaces: interfaces) response = request(payload) # The Node sidecar returns the true tracking ID, let's use it directly response['$jsii.byref'] ensure pop_pending_object end end |
#get_property(objref, property) ⇒ Object
Read an instance property on a JSII object.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'jsii/kernel/api.rb', line 78 def get_property(objref, property) objref_payload = if objref.respond_to?(:jsii_serialize) objref.jsii_serialize else { '$jsii.byref' => objref } end response = request({ api: 'get', objref: objref_payload, property: property }) Jsii::Serializer.load(response['value']) end |
#get_static(fqn, property) ⇒ Object
Read a static property on a JSII class.
135 136 137 138 139 140 141 142 |
# File 'jsii/kernel/api.rb', line 135 def get_static(fqn, property) response = request({ api: 'sget', fqn: fqn, property: property }) Jsii::Serializer.load(response['value']) end |
#load_assembly(name, version, tarball) ⇒ Hash
Tell the sidecar to load a JSII assembly from a tarball.
14 15 16 17 18 19 20 21 |
# File 'jsii/kernel/api.rb', line 14 def load_assembly(name, version, tarball) request({ api: 'load', name: name, version: version, tarball: tarball }) end |
#set_property(objref, property, value) ⇒ Hash
Write an instance property on a JSII object.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'jsii/kernel/api.rb', line 99 def set_property(objref, property, value) objref_payload = if objref.respond_to?(:jsii_serialize) objref.jsii_serialize else { '$jsii.byref' => objref } end request({ api: 'set', objref: objref_payload, property: property, value: Jsii::Serializer.dump(value) }) end |
#set_static(fqn, property, value) ⇒ Hash
Write a static property on a JSII class.
150 151 152 153 154 155 156 157 |
# File 'jsii/kernel/api.rb', line 150 def set_static(fqn, property, value) request({ api: 'sset', fqn: fqn, property: property, value: Jsii::Serializer.dump(value) }) end |