Module: JSI::SchemaModulePossibly
- Included in:
- NotASchemaModule
- Defined in:
- lib/jsi/schema_classes.rb
Overview
a JSI Schema module and a JSI::NotASchemaModule are both a SchemaModulePossibly. this module provides a #[] method.
Instance Attribute Summary collapse
-
#possibly_schema_node ⇒ Object
readonly
Returns the value of attribute possibly_schema_node.
Instance Method Summary collapse
-
#[](token) ⇒ Module, ...
subscripting a JSI schema module or a NotASchemaModule will subscript the node, and if the result is a JSI::Schema, return the JSI Schema module of that schema; if it is a PathedNode, return a NotASchemaModule; or if it is another value (a basic type), return that value.
-
#name_from_ancestor ⇒ String?
a name relative to a named schema module of an ancestor schema.
Instance Attribute Details
#possibly_schema_node ⇒ Object (readonly)
Returns the value of attribute possibly_schema_node.
188 189 190 |
# File 'lib/jsi/schema_classes.rb', line 188 def possibly_schema_node @possibly_schema_node end |
Instance Method Details
#[](token) ⇒ Module, ...
subscripting a JSI schema module or a NotASchemaModule will subscript the node, and if the result is a JSI::Schema, return the JSI Schema module of that schema; if it is a PathedNode, return a NotASchemaModule; or if it is another value (a basic type), return that value.
222 223 224 225 226 227 228 229 230 231 |
# File 'lib/jsi/schema_classes.rb', line 222 def [](token) sub = @possibly_schema_node[token] if sub.is_a?(JSI::Schema) sub.jsi_schema_module elsif sub.is_a?(JSI::PathedNode) NotASchemaModule.new(sub) else sub end end |
#name_from_ancestor ⇒ String?
a name relative to a named schema module of an ancestor schema.
for example, if Foos = JSI::JSONSchemaOrgDraft07.new_schema_module({'items' => {}})
then the module Foos.items will have a name_from_ancestor of "Foos.items"
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/jsi/schema_classes.rb', line 194 def name_from_ancestor schema_ancestors = [possibly_schema_node] + possibly_schema_node.jsi_parent_nodes named_parent_schema = schema_ancestors.detect { |jsi| jsi.is_a?(JSI::Schema) && jsi.jsi_schema_module.name } return nil unless named_parent_schema tokens = possibly_schema_node.jsi_ptr.ptr_relative_to(named_parent_schema.jsi_ptr).tokens name = named_parent_schema.jsi_schema_module.name parent = named_parent_schema tokens.each do |token| if parent.jsi_schemas.any? { |s| s.jsi_schema_module.jsi_property_accessors.include?(token) } name += ".#{token}" elsif [String, Numeric, TrueClass, FalseClass, NilClass].any? { |m| token.is_a?(m) } name += "[#{token.inspect}]" else return nil end parent = parent[token] end name end |