Class: JSI::Base

Inherits:
Object
  • Object
show all
Includes:
Schema::SchemaAncestorNode, Util::FingerprintHash
Defined in:
lib/jsi/base.rb

Overview

A JSI::Base instance represents a node in a JSON document (its #jsi_document) at a particular location (its #jsi_ptr), described by any number of JSON Schemas (its #jsi_schemas).

JSI::Base is an abstract base class. The subclasses used to instantiate JSIs are dynamically created as needed for a given instance.

These subclasses are generally intended to be ignored by applications using this library - the purpose they serve is to include modules relevant to the instance. The modules these classes include are:

Direct Known Subclasses

MetaschemaNode

Defined Under Namespace

Modules: ArrayNode, Enumerable, HashNode, StringNode Classes: SimpleNodeChildError

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::SchemaAncestorNode

#jsi_anchor_subschema, #jsi_anchor_subschemas, #jsi_resource_ancestor_uri

Constructor Details

#initialize(jsi_document, jsi_ptr: , jsi_indicated_schemas:, jsi_schema_base_uri: nil, jsi_schema_resource_ancestors: Util::EMPTY_ARY, jsi_schema_registry:, jsi_root_node: nil) ⇒ Base

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.

initializes a JSI whose instance is in the given document at the given pointer.

this is a private api - users should look elsewhere to instantiate JSIs, in particular:

Parameters:

  • jsi_document (Object)

    the document containing the instance

  • jsi_ptr (JSI::Ptr) (defaults to: )

    a pointer pointing to the JSI's instance in the document

  • jsi_schema_base_uri (Addressable::URI) (defaults to: nil)

    see SchemaSet#new_jsi param uri

  • jsi_schema_resource_ancestors (Array<JSI::Base + JSI::Schema>) (defaults to: Util::EMPTY_ARY)
  • jsi_root_node (JSI::Base) (defaults to: nil)

    the JSI of the root of the document containing this JSI

Raises:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/jsi/base.rb', line 109

def initialize(jsi_document,
    jsi_ptr: Ptr[],
    jsi_indicated_schemas: ,
    jsi_schema_base_uri: nil,
    jsi_schema_resource_ancestors: Util::EMPTY_ARY,
    jsi_schema_registry: ,
    jsi_root_node: nil
)
  raise(Bug, "no #jsi_schemas") unless respond_to?(:jsi_schemas)

  super()

  self.jsi_document = jsi_document
  self.jsi_ptr = jsi_ptr
  self.jsi_indicated_schemas = jsi_indicated_schemas
  self.jsi_schema_base_uri = jsi_schema_base_uri
  self.jsi_schema_resource_ancestors = jsi_schema_resource_ancestors
  self.jsi_schema_registry = jsi_schema_registry
  if @jsi_ptr.root?
    raise(Bug, "jsi_root_node specified for root JSI") if jsi_root_node
    @jsi_root_node = self
  else
    raise(Bug, "jsi_root_node is not JSI::Base") if !jsi_root_node.is_a?(JSI::Base)
    raise(Bug, "jsi_root_node ptr is not root") if !jsi_root_node.jsi_ptr.root?
    @jsi_root_node = jsi_root_node
  end

  jsi_memomaps_initialize

  if jsi_instance.is_a?(JSI::Base)
    raise(TypeError, "a JSI::Base instance must not be another JSI::Base. received: #{jsi_instance.pretty_inspect.chomp}")
  end
end

Instance Attribute Details

#jsi_documentObject (readonly)

document containing the instance of this JSI at our #jsi_ptr



152
153
154
# File 'lib/jsi/base.rb', line 152

def jsi_document
  @jsi_document
end

#jsi_indicated_schemasJSI::SchemaSet

the schemas indicated as describing this instance, prior to inplace application.

this is different from #jsi_schemas, which are the inplace applicator schemas which describe this instance. for most purposes, #jsi_schemas is more relevant.

jsi_indicated_schemas does not include inplace applicator schemas, such as the subschemas of allOf, whereas #jsi_schemas does.

this does include indicated schemas which do not apply themselves, such as $ref schemas (on json schema drafts up to 7) - these are not included on #jsi_schemas.

Returns:



183
184
185
# File 'lib/jsi/base.rb', line 183

def jsi_indicated_schemas
  @jsi_indicated_schemas
end

#jsi_ptrJSI::Ptr (readonly)

Ptr pointing to this JSI's instance within our #jsi_document

Returns:



156
157
158
# File 'lib/jsi/base.rb', line 156

def jsi_ptr
  @jsi_ptr
end

#jsi_root_nodeJSI::Base (readonly)

the JSI at the root of this JSI's document

Returns:



160
161
162
# File 'lib/jsi/base.rb', line 160

def jsi_root_node
  @jsi_root_node
end

Class Method Details

.inspectString

A string indicating the schema module name and/or schema URI of each schema the class represents.

Returns:

  • (String)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jsi/base.rb', line 33

def inspect
  if !respond_to?(:jsi_class_schemas)
    super
  else
    schema_names = jsi_class_schemas.map do |schema|
      mod_name = schema.jsi_schema_module.name_from_ancestor
      if mod_name && schema.schema_absolute_uri
        "#{mod_name} <#{schema.schema_absolute_uri}>"
      elsif mod_name
        mod_name
      elsif schema.schema_uri
        schema.schema_uri.to_s
      else
        schema.jsi_ptr.uri.to_s
      end
    end

    if schema_names.empty?
      "(JSI Schema Class for 0 schemas)"
    else
      -"(JSI Schema Class: #{schema_names.join(' + ')})"
    end
  end
end

.nameString

A constant name of this class. This is generated from any schema module name or URI of each schema this class represents, or random characters.

this generated name is not too pretty but can be more helpful than an anonymous class, especially in error messages.

Returns:

  • (String)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/jsi/base.rb', line 66

def name
  return super if instance_variable_defined?(:@tried_to_name)
  @tried_to_name = true
  return super unless respond_to?(:jsi_class_schemas)
  alnum = proc { |id| (id % 36**4).to_s(36).rjust(4, '0').upcase }
  schema_names = jsi_class_schemas.map do |schema|
    named_ancestor_schema, tokens = schema.jsi_schema_module.send(:named_ancestor_schema_tokens)
    if named_ancestor_schema
      [named_ancestor_schema.jsi_schema_module.name, *tokens].join('_')
    elsif schema.schema_uri
      schema.schema_uri.to_s
    else
      [alnum[schema.jsi_root_node.__id__], *schema.jsi_ptr.tokens].join('_')
    end
  end
  includes_names = jsi_class_includes.map { |m| m.name.sub(/\AJSI::Base::/, '').gsub(Util::RUBY_REJECT_NAME_RE, '_') }
  if schema_names.any?
    parts = schema_names.compact.sort.map { |n| 'X' + n.to_s }
    parts += includes_names
    const_name = Util.const_name_from_parts(parts, join: '__')
    const_name += "__" + alnum[__id__] if SchemaClasses.const_defined?(const_name)
  else
    const_name = (['X' + alnum[__id__]] + includes_names).join('__')
  end
  # collisions are technically possible though vanishingly unlikely
  SchemaClasses.const_set(const_name, self) unless SchemaClasses.const_defined?(const_name)
  super
end

.to_sString

A string indicating the schema module name and/or schema URI of each schema the class represents.

Returns:

  • (String)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/jsi/base.rb', line 58

def inspect
  if !respond_to?(:jsi_class_schemas)
    super
  else
    schema_names = jsi_class_schemas.map do |schema|
      mod_name = schema.jsi_schema_module.name_from_ancestor
      if mod_name && schema.schema_absolute_uri
        "#{mod_name} <#{schema.schema_absolute_uri}>"
      elsif mod_name
        mod_name
      elsif schema.schema_uri
        schema.schema_uri.to_s
      else
        schema.jsi_ptr.uri.to_s
      end
    end

    if schema_names.empty?
      "(JSI Schema Class for 0 schemas)"
    else
      -"(JSI Schema Class: #{schema_names.join(' + ')})"
    end
  end
end

Instance Method Details

#/(ptr) ⇒ JSI::Base

A shorthand alias for #jsi_descendent_node.

Note that, though more convenient to type, using an operator whose meaning may not be intuitive to a reader could impair readability of code.

examples:

my_jsi / ['foo', 'bar']
my_jsi / %w(foo bar)
my_schema / JSI::Ptr['additionalProperties']
my_schema / %w(properties foo items additionalProperties)

Parameters:

Returns:



330
331
332
# File 'lib/jsi/base.rb', line 330

def /(ptr)
  jsi_descendent_node(ptr)
end

#[](token, as_jsi: jsi_child_as_jsi_default, use_default: jsi_child_use_default_default) ⇒ JSI::Base, ...

subscripts to return a child value identified by the given token.

Parameters:

  • token (String, Integer, Object)

    an array index or hash key (JSON object property name) of the instance identifying the child value

  • as_jsi (:auto, true, false) (defaults to: jsi_child_as_jsi_default)

    (default is :auto) Whether to return the child as a JSI. One of:

    • :auto: By default a JSI will be returned when either:

      • the result is a complex value (responds to #to_ary or #to_hash)
      • the result is a schema (including true/false schemas)

    The plain content is returned when it is a simple type.

    • true: the result value will always be returned as a JSI. the #jsi_schemas of the result may be empty if no schemas describe the instance.
    • false: the result value will always be the plain instance.

    note that nil is returned (regardless of as_jsi) when there is no value to return because the token is not a hash key or array index of the instance and no default value applies. (one exception is when this JSI's instance is a Hash with a default or default_proc, which has unspecified behavior.)

  • use_default (true, false) (defaults to: jsi_child_use_default_default)

    (default is false) Whether to return a schema default value when the token refers to a child that is not in the document. If the token is not an array index or hash key of the instance, and one schema for the child instance specifies a default value, that default is returned.

    if the result with the default value is a JSI (per the as_jsi param), that JSI is not a child of this JSI - this JSI is not modified to fill in the default value. the result is a JSI within a new document containing the filled-in default.

    if the child instance's schemas do not indicate a single default value (that is, if zero or multiple defaults are specified across those schemas), nil is returned. (one exception is when this JSI's instance is a Hash with a default or default_proc, which has unspecified behavior.)

Returns:

  • (JSI::Base, Object, nil)

    the child value identified by the subscript token



467
468
469
470
# File 'lib/jsi/base.rb', line 467

def [](token, as_jsi: jsi_child_as_jsi_default, use_default: jsi_child_use_default_default)
  # note: overridden by Base::HashNode, Base::ArrayNode
  jsi_simple_node_child_error(token)
end

#[]=(token, value) ⇒ Object

assigns the subscript of the instance identified by the given token to the given value. if the value is a JSI, its instance is assigned instead of the JSI value itself.

Parameters:

  • token (String, Integer, Object)

    token identifying the subscript to assign

  • value (JSI::Base, Object)

    the value to be assigned



490
491
492
493
494
495
496
497
498
499
# File 'lib/jsi/base.rb', line 490

def []=(token, value)
  unless jsi_array? || jsi_hash?
    jsi_simple_node_child_error(token)
  end
  if value.is_a?(Base)
    self[token] = value.jsi_instance
  else
    jsi_instance[token] = value
  end
end

#as_json(options = {}) ⇒ Object

A structure coerced to JSONifiable types from the instance content. Calls Util#as_json with the instance and any given options.



651
652
653
# File 'lib/jsi/base.rb', line 651

def as_json(options = {})
  Util.as_json(jsi_instance, **options)
end

#described_by?(schema) ⇒ Boolean

Is this JSI described by the given schema (or schema module)?

Parameters:

Returns:

  • (Boolean)


511
512
513
514
515
516
517
518
519
# File 'lib/jsi/base.rb', line 511

def described_by?(schema)
  if schema.is_a?(Schema)
    jsi_schemas.include?(schema)
  elsif schema.is_a?(SchemaModule)
    jsi_schema_modules.include?(schema)
  else
    raise(TypeError, "expected a Schema or Schema Module; got: #{schema.pretty_inspect.chomp}")
  end
end

#dupObject



595
596
597
# File 'lib/jsi/base.rb', line 595

def dup
  jsi_modified_copy(&:dup)
end

#inspectString Also known as: to_s

a string representing this JSI, indicating any named schemas and inspecting its instance

Returns:

  • (String)


601
602
603
# File 'lib/jsi/base.rb', line 601

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

#jmespath_search(expression, **runtime_options) ⇒ Array, ...

queries this JSI using the JMESPath Ruby gem. see https://jmespath.org/ to learn the JMESPath query language.

the JMESPath gem is not a dependency of JSI, so must be installed / added to your Gemfile to use. e.g. gem 'jmespath', '~> 1.5'. note that versions below 1.5 are not compatible with JSI.

Parameters:

  • expression (String)

    a JMESPath expression

  • runtime_options

    passed to JMESPath.search, though no runtime_options are publicly documented or normally used.

Returns:



589
590
591
592
593
# File 'lib/jsi/base.rb', line 589

def jmespath_search(expression, **runtime_options)
  Util.require_jmespath

  JMESPath.search(expression, self, **runtime_options)
end

#jsi_ancestor_nodesArray<JSI::Base>

ancestor JSI instances from this node up to the root. this node itself is always its own first ancestor.

Returns:



295
296
297
298
299
300
301
302
303
304
305
# File 'lib/jsi/base.rb', line 295

def jsi_ancestor_nodes
  ancestors = []
  ancestor = jsi_root_node
  ancestors << ancestor

  jsi_ptr.tokens.each do |token|
    ancestor = ancestor[token, as_jsi: true]
    ancestors << ancestor
  end
  ancestors.reverse!.freeze
end

#jsi_array?Boolean

Is the instance an array?

An array is typically an instance of the Array class but may be an object that supports implicit conversion with a #to_ary method.

Returns:

  • (Boolean)


548
549
550
551
# File 'lib/jsi/base.rb', line 548

def jsi_array?
  # note: overridden by Base::ArrayNode
  false
end

#jsi_child_as_jsi_default:auto, ...

The default value for the param as_jsi of #[], controlling whether a child is returned as a JSI instance.

Returns:

  • (:auto, true, false)

    a valid value of the as_jsi param of #[]



474
475
476
# File 'lib/jsi/base.rb', line 474

def jsi_child_as_jsi_default
  :auto
end

#jsi_child_token_in_range?(token) ⇒ Boolean

Does the given token identify a child of this node?

In other words, is the given token an array index or hash key of the instance?

Always false if this is not a complex node.

Parameters:

  • token (String, Integer)

Returns:

  • (Boolean)


353
354
355
356
# File 'lib/jsi/base.rb', line 353

def jsi_child_token_in_range?(token)
  # note: overridden by Base::HashNode, Base::ArrayNode
  false
end

#jsi_child_use_default_defaulttrue, false

The default value for the param use_default of #[], controlling whether a schema default value is returned when a token refers to a child that is not in the document.

Returns:

  • (true, false)

    a valid value of the use_default param of #[]



481
482
483
# File 'lib/jsi/base.rb', line 481

def jsi_child_use_default_default
  false
end

#jsi_descendent_node(ptr) ⇒ JSI::Base

the descendent node at the given pointer

Parameters:

Returns:



311
312
313
314
# File 'lib/jsi/base.rb', line 311

def jsi_descendent_node(ptr)
  descendent = Ptr.ary_ptr(ptr).evaluate(self, as_jsi: true)
  descendent
end

#jsi_each_child_token {|String, Integer| ... } ⇒ nil, Enumerator

yields each token (array index or hash key) identifying a child node. yields nothing if this node is not complex or has no children.

Yields:

  • (String, Integer)

    each child token

Returns:

  • (nil, Enumerator)

    an Enumerator if invoked without a block; otherwise nil



339
340
341
342
343
# File 'lib/jsi/base.rb', line 339

def jsi_each_child_token
  # note: overridden by Base::HashNode, Base::ArrayNode
  return to_enum(__method__) { 0 } unless block_given?
  nil
end

#jsi_each_descendent_node(propertyNames: false) {|JSI::Base| ... } ⇒ nil, Enumerator

yields a JSI of each node at or below this one in this JSI's document.

Parameters:

  • propertyNames (Boolean) (defaults to: false)

    Whether to also yield each object property name (Hash key) of any descendent which is a hash/object. These are described by propertyNames subshemas of that object's schemas. They are not actual descendents of this node. See JSI::Base::HashNode#jsi_each_propertyName.

Yields:

  • (JSI::Base)

    each descendent node, starting with self

Returns:

  • (nil, Enumerator)

    an Enumerator if invoked without a block; otherwise nil



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/jsi/base.rb', line 194

def jsi_each_descendent_node(propertyNames: false, &block)
  return to_enum(__method__, propertyNames: propertyNames) unless block

  yield self

  if propertyNames && is_a?(HashNode)
    jsi_each_propertyName do |propertyName|
      propertyName.jsi_each_descendent_node(propertyNames: propertyNames, &block)
    end
  end

  jsi_each_child_token do |token|
    jsi_child(token, as_jsi: true).jsi_each_descendent_node(propertyNames: propertyNames, &block)
  end

  nil
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



664
665
666
667
668
669
670
671
672
673
674
# File 'lib/jsi/base.rb', line 664

def jsi_fingerprint
  {
    class: jsi_class,
    jsi_document: jsi_document,
    jsi_ptr: jsi_ptr,
    # for instances in documents with schemas:
    jsi_resource_ancestor_uri: jsi_resource_ancestor_uri,
    # different registries mean references may resolve to different resources so must not be equal
    jsi_schema_registry: jsi_schema_registry,
  }
end

#jsi_hash?Boolean

Is the instance a ruby Hash (JSON object)?

This is typically an instance of the Hash class but may be an object that supports implicit conversion with a #to_hash method.

Returns:

  • (Boolean)


560
561
562
563
# File 'lib/jsi/base.rb', line 560

def jsi_hash?
  # note: overridden by Base::HashNode
  false
end

#jsi_modified_copy {|Object| ... } ⇒ JSI::Base subclass

yields the content of this JSI's instance. the block must result in a modified copy of the yielded instance (not modified in place, which would alter this JSI as well) which will be used to instantiate and return a new JSI with the modified content.

the result may have different schemas which describe it than this JSI's schemas, if conditional applicator schemas apply differently to the modified instance.

Yields:

  • (Object)

    this JSI's instance. the block should result in a nondestructively modified copy of this.

Returns:

  • (JSI::Base subclass)

    the modified copy of self



531
532
533
534
535
536
537
538
539
# File 'lib/jsi/base.rb', line 531

def jsi_modified_copy(&block)
    modified_document = @jsi_ptr.modified_document_copy(@jsi_document, &block)
    modified_jsi_root_node = @jsi_root_node.jsi_indicated_schemas.new_jsi(modified_document,
      uri: @jsi_root_node.jsi_schema_base_uri,
      register: false, # default is already false but this is a place to be explicit
      schema_registry: jsi_schema_registry,
    )
    modified_jsi_root_node.jsi_descendent_node(@jsi_ptr)
end

#jsi_node_contentObject Also known as: jsi_instance

the content of this node in our #jsi_document at our #jsi_ptr. the same as #jsi_instance.



163
164
165
166
# File 'lib/jsi/base.rb', line 163

def jsi_node_content
  content = jsi_ptr.evaluate(jsi_document)
  content
end

#jsi_node_content_child(token) ⇒ Object?

The child of the #jsi_node_content identified by the given token, or nil if the token does not identify an existing child.

In other words, the element of the instance array at the given index, or the value of the instance hash/object for the given key.

Returns:

  • (Object, nil)

Raises:



366
367
368
369
# File 'lib/jsi/base.rb', line 366

def jsi_node_content_child(token)
  # note: overridden by Base::HashNode, Base::ArrayNode
  jsi_simple_node_child_error(token)
end

#jsi_parent_nodeJSI::Base?

the immediate parent of this JSI. nil if there is no parent.

Returns:



288
289
290
# File 'lib/jsi/base.rb', line 288

def jsi_parent_node
  jsi_ptr.root? ? nil : jsi_root_node.jsi_descendent_node(jsi_ptr.parent)
end

#jsi_parent_nodesArray<JSI::Base>

an array of JSI instances above this one in the document.

Returns:



275
276
277
278
279
280
281
282
283
# File 'lib/jsi/base.rb', line 275

def jsi_parent_nodes
  parent = jsi_root_node

  jsi_ptr.tokens.map do |token|
    parent.tap do
      parent = parent[token, as_jsi: true]
    end
  end.reverse!.freeze
end

#jsi_schema_modulesSet<Module>

the set of JSI schema modules corresponding to the schemas that describe this JSI

Returns:

  • (Set<Module>)


503
504
505
# File 'lib/jsi/base.rb', line 503

def jsi_schema_modules
  Util.ensure_module_set(jsi_schemas.map(&:jsi_schema_module))
end

#jsi_schemasJSI::SchemaSet

The set of schemas that describe this instance. These are the applicator schemas that apply to this instance, the result of inplace application of our #jsi_indicated_schemas.

Returns:



# File 'lib/jsi/base.rb', line 143

#jsi_select_descendents_leaf_first {|JSI::Base| ... } ⇒ JSI::Base

recursively selects descendent nodes of this JSI, returning a modified copy of self containing only descendent nodes for which the given block had a true-ish result.

this method recursively descends child nodes before yielding each node, so leaf nodes are yielded before their parents.

Yields:

  • (JSI::Base)

    each descendent node below self

Returns:

  • (JSI::Base)

    modified copy of self containing only the selected nodes



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/jsi/base.rb', line 250

def jsi_select_descendents_leaf_first(&block)
  jsi_modified_copy do |instance|
    if jsi_array? || jsi_hash?
      res = instance.class.new
      jsi_each_child_token do |token|
        v = jsi_child(token, as_jsi: true).jsi_select_descendents_leaf_first(&block)
        if yield(v)
          res_v = v.jsi_node_content
          if jsi_array?
            res << res_v
          else
            res[token] = res_v
          end
        end
      end
      res
    else
      instance
    end
  end
end

#jsi_select_descendents_node_first {|JSI::Base| ... } ⇒ JSI::Base

recursively selects descendent nodes of this JSI, returning a modified copy of self containing only descendent nodes for which the given block had a true-ish result.

this method yields a node before recursively descending to its child nodes, so leaf nodes are yielded last, after their parents. if a node is not selected, its descendents are never recursed.

Yields:

  • (JSI::Base)

    each descendent node below self

Returns:

  • (JSI::Base)

    modified copy of self containing only the selected nodes



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/jsi/base.rb', line 220

def jsi_select_descendents_node_first(&block)
  jsi_modified_copy do |instance|
    if jsi_array? || jsi_hash?
      res = instance.class.new
      jsi_each_child_token do |token|
        v = jsi_child(token, as_jsi: true)
        if yield(v)
          res_v = v.jsi_select_descendents_node_first(&block).jsi_node_content
          if jsi_array?
            res << res_v
          else
            res[token] = res_v
          end
        end
      end
      res
    else
      instance
    end
  end
end

#jsi_valid?Boolean

whether this JSI's instance is valid against all of its schemas

Returns:

  • (Boolean)


574
575
576
# File 'lib/jsi/base.rb', line 574

def jsi_valid?
  jsi_indicated_schemas.instance_valid?(self)
end

#jsi_validateJSI::Validation::FullResult

validates this JSI's instance against its schemas



568
569
570
# File 'lib/jsi/base.rb', line 568

def jsi_validate
  jsi_indicated_schemas.instance_validate(self)
end

#pretty_print(q)

This method returns an undefined value.

pretty-prints a representation of this JSI to the given printer



609
610
611
612
613
614
615
616
617
618
619
620
# File 'lib/jsi/base.rb', line 609

def pretty_print(q)
  q.text '#<'
  q.text jsi_object_group_text.join(' ')
  q.group_sub {
    q.nest(2) {
      q.breakable ' '
      q.pp jsi_instance
    }
  }
  q.breakable ''
  q.text '>'
end

#to_json(options = {}) ⇒ String

A JSON encoded string of the instance content. Calls Util#to_json with the instance and any given options.

Returns:

  • (String)


658
659
660
# File 'lib/jsi/base.rb', line 658

def to_json(options = {})
  Util.to_json(jsi_instance, **options)
end