Class: JSI::Base
- Inherits:
-
Object
- Object
- JSI::Base
- 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:
- the Schema#jsi_schema_module of each schema which describes the instance
- HashNode, ArrayNode, or StringNode if the instance is a hash/object, array, or string
- Modules defining accessor methods for property names described by the schemas
Direct Known Subclasses
Defined Under Namespace
Modules: ArrayNode, Enumerable, HashNode, StringNode Classes: SimpleNodeChildError
Instance Attribute Summary collapse
-
#jsi_document ⇒ Object
readonly
document containing the instance of this JSI at our #jsi_ptr.
-
#jsi_indicated_schemas ⇒ JSI::SchemaSet
readonly
the schemas indicated as describing this instance, prior to inplace application.
-
#jsi_ptr ⇒ JSI::Ptr
readonly
Ptr pointing to this JSI's instance within our #jsi_document.
-
#jsi_root_node ⇒ JSI::Base
readonly
the JSI at the root of this JSI's document.
Attributes included from Schema::SchemaAncestorNode
#jsi_schema_base_uri, #jsi_schema_registry, #jsi_schema_resource_ancestors
Class Method Summary collapse
-
.inspect ⇒ String
A string indicating the schema module name and/or schema URI of each schema the class represents.
-
.name ⇒ String
A constant name of this class.
-
.to_s ⇒ String
A string indicating the schema module name and/or schema URI of each schema the class represents.
Instance Method Summary collapse
-
#/(ptr) ⇒ JSI::Base
A shorthand alias for #jsi_descendent_node.
-
#[](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.
-
#[]=(token, value) ⇒ Object
assigns the subscript of the instance identified by the given token to the given value.
-
#as_json(options = {}) ⇒ Object
A structure coerced to JSONifiable types from the instance content.
-
#described_by?(schema) ⇒ Boolean
Is this JSI described by the given schema (or schema module)?.
- #dup ⇒ Object
-
#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
constructor
private
initializes a JSI whose instance is in the given document at the given pointer.
-
#inspect ⇒ String
(also: #to_s)
a string representing this JSI, indicating any named schemas and inspecting its instance.
-
#jmespath_search(expression, **runtime_options) ⇒ Array, ...
queries this JSI using the JMESPath Ruby gem.
-
#jsi_ancestor_nodes ⇒ Array<JSI::Base>
ancestor JSI instances from this node up to the root.
-
#jsi_array? ⇒ Boolean
Is the instance an array?.
-
#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. -
#jsi_child_token_in_range?(token) ⇒ Boolean
Does the given token identify a child of this node?.
-
#jsi_child_use_default_default ⇒ true, 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. -
#jsi_descendent_node(ptr) ⇒ JSI::Base
the descendent node at the given pointer.
-
#jsi_each_child_token {|String, Integer| ... } ⇒ nil, Enumerator
yields each token (array index or hash key) identifying a child node.
-
#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.
- #jsi_fingerprint ⇒ Object private
-
#jsi_hash? ⇒ Boolean
Is the instance a ruby Hash (JSON object)?.
-
#jsi_modified_copy {|Object| ... } ⇒ JSI::Base subclass
yields the content of this JSI's instance.
-
#jsi_node_content ⇒ Object
(also: #jsi_instance)
the content of this node in our #jsi_document at our #jsi_ptr.
-
#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. -
#jsi_parent_node ⇒ JSI::Base?
the immediate parent of this JSI.
-
#jsi_parent_nodes ⇒ Array<JSI::Base>
an array of JSI instances above this one in the document.
-
#jsi_schema_modules ⇒ Set<Module>
the set of JSI schema modules corresponding to the schemas that describe this JSI.
-
#jsi_schemas ⇒ JSI::SchemaSet
The set of schemas that describe this instance.
-
#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.
-
#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.
-
#jsi_valid? ⇒ Boolean
whether this JSI's instance is valid against all of its schemas.
-
#jsi_validate ⇒ JSI::Validation::FullResult
validates this JSI's instance against its schemas.
-
#pretty_print(q)
pretty-prints a representation of this JSI to the given printer.
-
#to_json(options = {}) ⇒ String
A JSON encoded string of the instance content.
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:
- JSI.new_schema and Schema::DescribesSchema#new_schema to instantiate schemas
- Schema#new_jsi to instantiate schema instances
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_document ⇒ Object (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_schemas ⇒ JSI::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
.
183 184 185 |
# File 'lib/jsi/base.rb', line 183 def jsi_indicated_schemas @jsi_indicated_schemas end |
#jsi_ptr ⇒ JSI::Ptr (readonly)
Ptr pointing to this JSI's instance within our #jsi_document
156 157 158 |
# File 'lib/jsi/base.rb', line 156 def jsi_ptr @jsi_ptr end |
#jsi_root_node ⇒ JSI::Base (readonly)
the JSI at the root of this JSI's document
160 161 162 |
# File 'lib/jsi/base.rb', line 160 def jsi_root_node @jsi_root_node end |
Class Method Details
.inspect ⇒ String
A string indicating the schema module name and/or schema URI of each schema the class represents.
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 |
.name ⇒ String
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.
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_s ⇒ String
A string indicating the schema module name and/or schema URI of each schema the class represents.
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)
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.
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.
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( = {}) Util.as_json(jsi_instance, **) end |
#described_by?(schema) ⇒ Boolean
Is this JSI described by the given schema (or schema module)?
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 |
#dup ⇒ Object
595 596 597 |
# File 'lib/jsi/base.rb', line 595 def dup jsi_modified_copy(&:dup) end |
#inspect ⇒ String Also known as: to_s
a string representing this JSI, indicating any named schemas and inspecting its instance
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.
589 590 591 592 593 |
# File 'lib/jsi/base.rb', line 589 def jmespath_search(expression, **) Util.require_jmespath JMESPath.search(expression, self, **) end |
#jsi_ancestor_nodes ⇒ Array<JSI::Base>
ancestor JSI instances from this node up to the root. this node itself is always its own first ancestor.
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.
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.
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.
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_default ⇒ true, 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.
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
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.
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.
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_fingerprint ⇒ Object
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.
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.
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.
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_content ⇒ Object 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.
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_node ⇒ JSI::Base?
the immediate parent of this JSI. nil if there is no parent.
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_nodes ⇒ Array<JSI::Base>
an array of JSI instances above this one in the document.
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_modules ⇒ Set<Module>
the set of JSI schema modules corresponding to the schemas that describe this JSI
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_schemas ⇒ JSI::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.
|
# 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.
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.
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
574 575 576 |
# File 'lib/jsi/base.rb', line 574 def jsi_valid? jsi_indicated_schemas.instance_valid?(self) end |
#jsi_validate ⇒ JSI::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.
658 659 660 |
# File 'lib/jsi/base.rb', line 658 def to_json( = {}) Util.to_json(jsi_instance, **) end |