lib/jsi/schema/schema_ancestor_node.rb in jsi-0.6.0 vs lib/jsi/schema/schema_ancestor_node.rb in jsi-0.7.0
- old
+ new
@@ -5,40 +5,36 @@
# tracking things necessary for a schema to function correctly
module Schema::SchemaAncestorNode
# the base URI used to resolve the ids of schemas at or below this JSI.
# this is always an absolute URI (with no fragment).
# this may be the absolute schema URI of a parent schema or the URI from which the document was retrieved.
- # @private
+ # @api private
# @return [Addressable::URI, nil]
attr_reader :jsi_schema_base_uri
# resources which are ancestors of this JSI in the document. this does not include self.
- # @private
+ # @api private
# @return [Array<JSI::Schema>]
def jsi_schema_resource_ancestors
return @jsi_schema_resource_ancestors if instance_variable_defined?(:@jsi_schema_resource_ancestors)
- [].freeze
+ Util::EMPTY_ARY
end
# the URI of the resource containing this node.
# this is always an absolute URI (with no fragment).
# if this node is a schema with an id, this is its absolute URI; otherwise a parent resource's URI,
# or nil if not contained by a resource with a URI.
# @return [Addressable::URI, nil]
def jsi_resource_ancestor_uri
- if is_a?(Schema) && schema_absolute_uri
- schema_absolute_uri
- else
- jsi_schema_base_uri
- end
+ (is_a?(Schema) && schema_absolute_uri) || jsi_schema_base_uri
end
# a schema at or below this node with the given anchor.
#
# @return [JSI::Schema, nil]
def jsi_anchor_subschema(anchor)
- subschemas = jsi_anchor_subschemas_map[anchor]
+ subschemas = jsi_anchor_subschemas_map[anchor: anchor]
if subschemas.size == 1
subschemas.first
else
nil
end
@@ -46,23 +42,21 @@
# schemas at or below node with the given anchor.
#
# @return [Array<JSI::Schema>]
def jsi_anchor_subschemas(anchor)
- jsi_anchor_subschemas_map[anchor]
+ jsi_anchor_subschemas_map[anchor: anchor]
end
private
def jsi_document=(jsi_document)
@jsi_document = jsi_document
end
def jsi_ptr=(jsi_ptr)
- unless jsi_ptr.is_a?(Ptr)
- raise(TypeError, "jsi_ptr must be a JSI::Ptr; got: #{jsi_ptr.inspect}")
- end
+ raise(Bug, "jsi_ptr not #{Ptr}: #{jsi_ptr.inspect}") unless jsi_ptr.is_a?(Ptr)
@jsi_ptr = jsi_ptr
end
def jsi_schema_base_uri=(jsi_schema_base_uri)
if jsi_schema_base_uri
@@ -81,11 +75,11 @@
def jsi_schema_resource_ancestors=(jsi_schema_resource_ancestors)
if jsi_schema_resource_ancestors
unless jsi_schema_resource_ancestors.respond_to?(:to_ary)
raise(TypeError, "jsi_schema_resource_ancestors must be an array; got: #{jsi_schema_resource_ancestors.inspect}")
end
- jsi_schema_resource_ancestors.each { |a| Schema.ensure_schema(a) }
+ jsi_schema_resource_ancestors.each { |a| Schema.ensure_schema(a) }
# sanity check the ancestors are in order
last_anc_ptr = nil
jsi_schema_resource_ancestors.each do |anc|
if last_anc_ptr.nil?
# pass
@@ -102,16 +96,16 @@
last_anc_ptr = anc.jsi_ptr
end
@jsi_schema_resource_ancestors = jsi_schema_resource_ancestors.to_ary.freeze
else
- @jsi_schema_resource_ancestors = [].freeze
+ @jsi_schema_resource_ancestors = Util::EMPTY_ARY
end
end
def jsi_anchor_subschemas_map
- jsi_memomap(__method__) do |anchor|
- jsi_each_child_node.select do |node|
+ jsi_memomap(__method__) do |anchor: |
+ jsi_each_descendent_node.select do |node|
node.is_a?(Schema) && node.respond_to?(:anchor) && node.anchor == anchor
end.freeze
end
end
end