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
-
#jsi_node ⇒ Object
readonly
Returns the value of attribute jsi_node.
Instance Method Summary collapse
-
#[](token, **kw) { ... } ⇒ Module, ...
Subscripting a JSI schema module or a 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.
-
#name_from_ancestor ⇒ String?
private
a name relative to a named schema module of an ancestor schema.
Instance Attribute Details
#jsi_node ⇒ Object (readonly)
Returns the value of attribute jsi_node.
259 260 261 |
# File 'lib/jsi/schema_classes.rb', line 259 def jsi_node @jsi_node end |
Instance Method Details
#[](token, **kw) { ... } ⇒ Module, ...
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.
294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/jsi/schema_classes.rb', line 294 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_ancestor ⇒ String?
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"
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/jsi/schema_classes.rb', line 266 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 end |