Skip to content

Commit

Permalink
rename metaschema_instance_modules to schema_implementation_modules
Browse files Browse the repository at this point in the history
this is a param of Schema#describes_schema! and MetaschemaNode#initialize
this name is more descriptive of what the modules do and less confusing with jsi_schema_module (if a 'metaschema instance' is a schema, metaschema_instance_module seems to mean about the same thing as schema_module, which is confusing)
  • Loading branch information
notEthan committed Mar 21, 2022
1 parent 63929cd commit c997a39
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 38 deletions.
24 changes: 12 additions & 12 deletions lib/jsi/metaschema_node.rb
Expand Up @@ -25,17 +25,17 @@ class MetaschemaNode < Base

# @param jsi_document the document containing the metaschema
# @param jsi_ptr [JSI::Ptr] ptr to this MetaschemaNode in jsi_document
# @param metaschema_instance_modules [Enumerable<Module>] modules which implement the functionality of the
# schema. these are included on the {Schema#jsi_schema_module} of the metaschema.
# @param schema_implementation_modules [Enumerable<Module>] modules which implement the functionality
# of the schema. these are included on the {Schema#jsi_schema_module} of the metaschema.
# they extend any schema described by the metaschema, including those in the document containing
# the metaschema, and the metaschema itself.
# see {Schema#describes_schema!} param `metaschema_instance_modules`.
# see {Schema#describes_schema!} param `schema_implementation_modules`.
# @param metaschema_root_ptr [JSI::Ptr] ptr to the root of the metaschema in the jsi_document
# @param root_schema_ptr [JSI::Ptr] ptr to the schema describing the root of the jsi_document
def initialize(
jsi_document,
jsi_ptr: Ptr[],
metaschema_instance_modules: ,
schema_implementation_modules: ,
metaschema_root_ptr: Ptr[],
root_schema_ptr: Ptr[],
jsi_schema_base_uri: nil,
Expand All @@ -45,7 +45,7 @@ def initialize(

self.jsi_document = jsi_document
self.jsi_ptr = jsi_ptr
@metaschema_instance_modules = Util.ensure_module_set(metaschema_instance_modules)
@schema_implementation_modules = Util.ensure_module_set(schema_implementation_modules)
@metaschema_root_ptr = metaschema_root_ptr
@root_schema_ptr = root_schema_ptr
raise(Bug, 'jsi_root_node') if jsi_ptr.root? ^ !jsi_root_node
Expand All @@ -66,7 +66,7 @@ def initialize(
end

instance_for_schemas = jsi_document
bootstrap_schema_class = JSI::SchemaClasses.bootstrap_schema_class(metaschema_instance_modules)
bootstrap_schema_class = JSI::SchemaClasses.bootstrap_schema_class(schema_implementation_modules)
root_bootstrap_schema = bootstrap_schema_class.new(
jsi_document,
jsi_ptr: root_schema_ptr,
Expand All @@ -82,8 +82,8 @@ def initialize(
our_bootstrap_schemas.each do |bootstrap_schema|
if bootstrap_schema.jsi_ptr == metaschema_root_ptr
# this is described by the metaschema, i.e. this is a schema
metaschema_instance_modules.each do |metaschema_instance_module|
extend metaschema_instance_module
schema_implementation_modules.each do |schema_implementation_module|
extend schema_implementation_module
end
end
if bootstrap_schema.jsi_ptr == jsi_ptr
Expand All @@ -108,7 +108,7 @@ def initialize(

# note: jsi_schemas must already be set for jsi_schema_module to be used/extended
if is_a?(Metaschema)
describes_schema!(metaschema_instance_modules)
describes_schema!(schema_implementation_modules)
end

@jsi_schemas.each do |schema|
Expand All @@ -124,14 +124,14 @@ def initialize(
addtlItemsanyOf = metaschema_root_ptr["properties"]["additionalItems"]["anyOf"]

if !jsi_ptr.root? && [addtlPropsanyOf, addtlItemsanyOf].include?(jsi_ptr.parent)
describes_schema!(metaschema_instance_modules)
describes_schema!(schema_implementation_modules)
end
end
end

# Set of modules to apply to schemas which are instances of (described by) the metaschema
# @return [Set<Module>]
attr_reader :metaschema_instance_modules
attr_reader :schema_implementation_modules

# ptr to the root of the metaschema in the jsi_document
# @return [JSI::Ptr]
Expand Down Expand Up @@ -223,7 +223,7 @@ def jsi_fingerprint
def our_initialize_params
{
jsi_ptr: jsi_ptr,
metaschema_instance_modules: metaschema_instance_modules,
schema_implementation_modules: schema_implementation_modules,
metaschema_root_ptr: metaschema_root_ptr,
root_schema_ptr: root_schema_ptr,
jsi_schema_base_uri: jsi_schema_base_uri,
Expand Down
12 changes: 6 additions & 6 deletions lib/jsi/metaschema_node/bootstrap_schema.rb
Expand Up @@ -8,7 +8,7 @@ module JSI
# Schema#subschema and Schema#resource_root_subschema are the intended mechanisms to instantiate subschemas
# and resolve references. #[] and #jsi_root_node are not implemented.
#
# metaschema instance modules are attached to generated subclasses of BootstrapSchema by
# schema implementation modules are attached to generated subclasses of BootstrapSchema by
# {SchemaClasses.bootstrap_schema_class}. that subclass is instantiated with a document and
# pointer, representing a schema.
#
Expand All @@ -23,7 +23,7 @@ def inspect
if self == MetaschemaNode::BootstrapSchema
name
else
"#{name || MetaschemaNode::BootstrapSchema.name} (#{metaschema_instance_modules.map(&:inspect).join(', ')})"
"#{name || MetaschemaNode::BootstrapSchema.name} (#{schema_implementation_modules.map(&:inspect).join(', ')})"
end
end

Expand All @@ -37,8 +37,8 @@ def initialize(
jsi_ptr: Ptr[],
jsi_schema_base_uri: nil
)
unless respond_to?(:metaschema_instance_modules)
raise(TypeError, "cannot instantiate #{self.class.inspect} which has no method #metaschema_instance_modules")
unless respond_to?(:schema_implementation_modules)
raise(TypeError, "cannot instantiate #{self.class.inspect} which has no method #schema_implementation_modules")
end

jsi_initialize_memos
Expand Down Expand Up @@ -83,7 +83,7 @@ def pretty_print(q)
def jsi_object_group_text
[
self.class.name || MetaschemaNode::BootstrapSchema.name,
"(#{metaschema_instance_modules.map(&:inspect).join(', ')})",
"(#{schema_implementation_modules.map(&:inspect).join(', ')})",
jsi_ptr.uri,
]
end
Expand All @@ -94,7 +94,7 @@ def jsi_fingerprint
class: self.class,
jsi_ptr: @jsi_ptr,
jsi_document: @jsi_document,
metaschema_instance_modules: metaschema_instance_modules,
schema_implementation_modules: schema_implementation_modules,
}
end
end
Expand Down
20 changes: 10 additions & 10 deletions lib/jsi/schema.rb
Expand Up @@ -434,30 +434,30 @@ def jsi_schema_instance_modules=(jsi_schema_instance_modules)
# this schema is extended with {DescribesSchema} and its {#jsi_schema_module} is extended
# with {DescribesSchemaModule}, and the JSI Schema Module will include the given modules.
#
# @param metaschema_instance_modules [Enumerable<Module>] modules which implement the functionality of
# @param schema_implementation_modules [Enumerable<Module>] modules which implement the functionality of
# the schema to extend schemas described by this schema.
# this must include JSI::Schema (usually indirectly).
# @return [void]
def describes_schema!(metaschema_instance_modules)
metaschema_instance_modules = Util.ensure_module_set(metaschema_instance_modules)
def describes_schema!(schema_implementation_modules)
schema_implementation_modules = Util.ensure_module_set(schema_implementation_modules)

unless metaschema_instance_modules.any? { |mod| mod <= Schema }
raise(ArgumentError, "metaschema_instance_modules for a schema must include #{Schema}")
unless schema_implementation_modules.any? { |mod| mod <= Schema }
raise(ArgumentError, "schema_implementation_modules for a schema must include #{Schema}")
end

if describes_schema?
# this schema, or one equal to it, has already had describes_schema! called on it.
# this is to be avoided, but is not particularly a problem.
# it is a bug if it was called different times with different metaschema_instance_modules, though.
unless jsi_schema_module.metaschema_instance_modules == metaschema_instance_modules
raise(ArgumentError, "this schema already describes a schema with different metaschema_instance_modules")
# it is a bug if it was called different times with different schema_implementation_modules, though.
unless jsi_schema_module.schema_implementation_modules == schema_implementation_modules
raise(ArgumentError, "this schema already describes a schema with different schema_implementation_modules")
end
else
metaschema_instance_modules.each do |mod|
schema_implementation_modules.each do |mod|
jsi_schema_module.include(mod)
end
jsi_schema_module.extend(DescribesSchemaModule)
jsi_schema_module.instance_variable_set(:@metaschema_instance_modules, metaschema_instance_modules)
jsi_schema_module.instance_variable_set(:@schema_implementation_modules, schema_implementation_modules)
end

extend(DescribesSchema)
Expand Down
8 changes: 4 additions & 4 deletions lib/jsi/schema_classes.rb
Expand Up @@ -57,7 +57,7 @@ def new_schema_module(schema_content, **kw)
end

# @return [Set<Module>]
attr_reader :metaschema_instance_modules
attr_reader :schema_implementation_modules
end

# this module is a namespace for building schema classes and schema modules.
Expand Down Expand Up @@ -88,14 +88,14 @@ def class_for_schemas(schemas)

# a subclass of MetaschemaNode::BootstrapSchema with the given modules included
# @api private
# @param modules [Set<Module>] metaschema instance modules
# @param modules [Set<Module>] schema implementation modules
# @return [Class]
def bootstrap_schema_class(modules)
modules = Util.ensure_module_set(modules)
jsi_memoize(__method__, modules: modules) do |modules: |
Class.new(MetaschemaNode::BootstrapSchema).instance_exec(modules) do |modules|
define_singleton_method(:metaschema_instance_modules) { modules }
define_method(:metaschema_instance_modules) { modules }
define_singleton_method(:schema_implementation_modules) { modules }
define_method(:schema_implementation_modules) { modules }
modules.each { |mod| include(mod) }

self
Expand Down
2 changes: 1 addition & 1 deletion lib/jsi/simple_wrap.rb
Expand Up @@ -19,7 +19,7 @@ def internal_validate_keywords(result_builder)
end
end

simple_wrap_metaschema = MetaschemaNode.new(nil, metaschema_instance_modules: [simple_wrap_implementation])
simple_wrap_metaschema = MetaschemaNode.new(nil, schema_implementation_modules: [simple_wrap_implementation])
SimpleWrap = simple_wrap_metaschema.new_schema_module({})

# SimpleWrap is a JSI schema module which recursively wraps nested structures
Expand Down
2 changes: 1 addition & 1 deletion lib/schemas/json-schema.org/draft-04/schema.rb
Expand Up @@ -3,7 +3,7 @@
module JSI
metaschema_document = ::JSON.parse(SCHEMAS_PATH.join('json-schema.org/draft-04/schema.json').read)
JSONSchemaOrgDraft04 = MetaschemaNode.new(metaschema_document,
metaschema_instance_modules: [JSI::Schema::Draft04],
schema_implementation_modules: [JSI::Schema::Draft04],
).jsi_schema_module

# the JSI schema module for `http://json-schema.org/draft-04/schema`
Expand Down
2 changes: 1 addition & 1 deletion lib/schemas/json-schema.org/draft-06/schema.rb
Expand Up @@ -3,7 +3,7 @@
module JSI
metaschema_document = ::JSON.parse(SCHEMAS_PATH.join('json-schema.org/draft-06/schema.json').read)
JSONSchemaOrgDraft06 = MetaschemaNode.new(metaschema_document,
metaschema_instance_modules: [JSI::Schema::Draft06],
schema_implementation_modules: [JSI::Schema::Draft06],
).jsi_schema_module

# the JSI schema module for `http://json-schema.org/draft-06/schema`
Expand Down
2 changes: 1 addition & 1 deletion lib/schemas/json-schema.org/draft-07/schema.rb
Expand Up @@ -3,7 +3,7 @@
module JSI
metaschema_document = ::JSON.parse(SCHEMAS_PATH.join('json-schema.org/draft-07/schema.json').read)
JSONSchemaOrgDraft07 = MetaschemaNode.new(metaschema_document,
metaschema_instance_modules: [JSI::Schema::Draft07],
schema_implementation_modules: [JSI::Schema::Draft07],
).jsi_schema_module

# the JSI schema module for `http://json-schema.org/draft-07/schema`
Expand Down
4 changes: 2 additions & 2 deletions test/metaschema_node_test.rb
@@ -1,15 +1,15 @@
require_relative 'test_helper'

describe JSI::MetaschemaNode do
let(:metaschema_instance_modules) do
let(:schema_implementation_modules) do
[
JSI::Schema,
JSI::Schema::Application::Draft06,
]
end
let(:root_node) do
JSI::MetaschemaNode.new(jsi_document,
metaschema_instance_modules: metaschema_instance_modules,
schema_implementation_modules: schema_implementation_modules,
metaschema_root_ptr: metaschema_root_ptr,
root_schema_ptr: root_schema_ptr,
)
Expand Down

0 comments on commit c997a39

Please sign in to comment.