Skip to content

Commit

Permalink
Base#jsi_resource_ancestor_uri (in Schema::SchemaAncestorNode) replac…
Browse files Browse the repository at this point in the history
…es Schema#jsi_subschema_base_uri
  • Loading branch information
notEthan committed Oct 16, 2021
1 parent 0baa9fe commit 8b79deb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/jsi/base.rb
Expand Up @@ -468,7 +468,7 @@ def jsi_fingerprint
jsi_document: jsi_document,
jsi_ptr: jsi_ptr,
# for instances in documents with schemas:
jsi_schema_base_uri: is_a?(Schema) ? jsi_subschema_base_uri : jsi_schema_base_uri,
jsi_schema_base_uri: jsi_resource_ancestor_uri,
# only defined for JSI::Schema instances:
jsi_schema_instance_modules: is_a?(Schema) ? jsi_schema_instance_modules : nil,
}
Expand Down Expand Up @@ -497,7 +497,7 @@ def jsi_subinstance_memos
jsi_document: @jsi_document,
jsi_ptr: @jsi_ptr[token],
jsi_root_node: @jsi_root_node,
jsi_schema_base_uri: is_a?(Schema) ? jsi_subschema_base_uri : jsi_schema_base_uri,
jsi_schema_base_uri: jsi_resource_ancestor_uri,
jsi_schema_resource_ancestors: is_a?(Schema) ? jsi_subschema_resource_ancestors : jsi_schema_resource_ancestors,
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jsi/metaschema_node.rb
Expand Up @@ -228,7 +228,7 @@ def jsi_subinstance_memos
jsi_memomap(:subinstance) do |token|
new_node(
jsi_ptr: jsi_ptr[token],
jsi_schema_base_uri: is_a?(Schema) ? jsi_subschema_base_uri : jsi_schema_base_uri,
jsi_schema_base_uri: jsi_resource_ancestor_uri,
)
end
end
Expand Down
13 changes: 1 addition & 12 deletions lib/jsi/schema.rb
Expand Up @@ -392,7 +392,7 @@ def subschema_map
self.class.new(
jsi_document,
jsi_ptr: jsi_ptr + subptr,
jsi_schema_base_uri: jsi_subschema_base_uri,
jsi_schema_base_uri: jsi_resource_ancestor_uri,
)
else
Schema.ensure_schema(subptr.evaluate(self, as_jsi: true), msg: [
Expand Down Expand Up @@ -512,17 +512,6 @@ def validate_schema!
raise(NotImplementedError, "Schema#validate_schema! removed")
end

# @private
# @return [Addressable::URI, nil] the base URI for any subschemas below this schema.
# this is always an absolute URI (with no fragment).
def jsi_subschema_base_uri
if schema_absolute_uri
schema_absolute_uri
else
jsi_schema_base_uri
end
end

# @private
# @return [Array<JSI::Schema>] schema resources which are ancestors of any subschemas below this schema.
# this may include this JSI if this is a schema resource root.
Expand Down
4 changes: 2 additions & 2 deletions lib/jsi/schema/ref.rb
Expand Up @@ -56,8 +56,8 @@ def deref_schema

if ref_uri_nofrag.absolute?
ref_abs_uri = ref_uri_nofrag
elsif ref_schema && ref_schema.jsi_subschema_base_uri
ref_abs_uri = ref_schema.jsi_subschema_base_uri.join(ref_uri_nofrag)
elsif ref_schema && ref_schema.jsi_resource_ancestor_uri
ref_abs_uri = ref_schema.jsi_resource_ancestor_uri.join(ref_uri_nofrag)
else
ref_abs_uri = nil
end
Expand Down
12 changes: 12 additions & 0 deletions lib/jsi/schema/schema_ancestor_node.rb
Expand Up @@ -16,6 +16,18 @@ def jsi_schema_resource_ancestors
[].freeze
end

# @return [Addressable::URI, nil] 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.
def jsi_resource_ancestor_uri
if is_a?(Schema) && schema_absolute_uri
schema_absolute_uri
else
jsi_schema_base_uri
end
end

private

def jsi_document=(jsi_document)
Expand Down

0 comments on commit 8b79deb

Please sign in to comment.