Module: JSI::SchemaClasses
- Defined in:
- lib/jsi/schema_classes.rb
Overview
this module is a namespace for building schema classes and schema modules.
Class Method Summary collapse
-
.accessor_module_for_schema(schema, conflicting_modules:, setters: true) ⇒ Object
deprecated
Deprecated.
after v0.7
-
.bootstrap_schema_class(modules) ⇒ Class
private
a subclass of MetaschemaNode::BootstrapSchema with the given modules included.
-
.class_for_schemas(schemas, includes:) ⇒ Class subclassing JSI::Base
private
a JSI Schema Class which represents the given schemas.
- .includes_for(instance) ⇒ Set<Module> private
- .module_for_schema(schema) ⇒ Module + SchemaModule private
-
.schema_property_reader_module(schema, conflicting_modules:) ⇒ Module
private
a module of readers for described property names of the given schema.
-
.schema_property_writer_module(schema, conflicting_modules:) ⇒ Object
private
a module of writers for described property names of the given schema.
Class Method Details
.accessor_module_for_schema(schema, conflicting_modules:, setters: true) ⇒ Object
after v0.7
183 184 185 186 187 188 |
# File 'lib/jsi/schema_classes.rb', line 183 def accessor_module_for_schema(schema, conflicting_modules: , setters: true) Module.new do include SchemaClasses.schema_property_reader_module(schema, conflicting_modules: conflicting_modules) include SchemaClasses.schema_property_writer_module(schema, conflicting_modules: conflicting_modules) if setters end end |
.bootstrap_schema_class(modules) ⇒ Class
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 subclass of MetaschemaNode::BootstrapSchema with the given modules included
153 154 155 156 157 |
# File 'lib/jsi/schema_classes.rb', line 153 def bootstrap_schema_class(modules) @bootstrap_schema_class_map[ modules: Util.ensure_module_set(modules), ] end |
.class_for_schemas(schemas, includes:) ⇒ Class subclassing JSI::Base
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 JSI Schema Class which represents the given schemas. an instance of the class is a JSON Schema instance described by all of the given schemas.
111 112 113 114 115 116 |
# File 'lib/jsi/schema_classes.rb', line 111 def class_for_schemas(schemas, includes: ) @class_for_schemas_map[ schemas: SchemaSet.ensure_schema_set(schemas), includes: Util.ensure_module_set(includes), ] end |
.includes_for(instance) ⇒ Set<Module>
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.
97 98 99 100 101 102 103 |
# File 'lib/jsi/schema_classes.rb', line 97 def includes_for(instance) includes = Set[] includes << Base::ArrayNode if instance.respond_to?(:to_ary) includes << Base::HashNode if instance.respond_to?(:to_hash) includes << Base::StringNode if instance.respond_to?(:to_str) includes.freeze end |
.module_for_schema(schema) ⇒ Module + SchemaModule
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.
172 173 174 175 176 |
# File 'lib/jsi/schema_classes.rb', line 172 def module_for_schema(schema) Schema.ensure_schema(schema) raise(Bug, "non-Base schema cannot have schema module: #{schema}") unless schema.is_a?(Base) @schema_module_map[schema: schema] end |
.schema_property_reader_module(schema, conflicting_modules:) ⇒ Module
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 module of readers for described property names of the given schema.
198 199 200 201 |
# File 'lib/jsi/schema_classes.rb', line 198 def schema_property_reader_module(schema, conflicting_modules: ) Schema.ensure_schema(schema) @schema_property_reader_module_map[schema: schema, conflicting_modules: conflicting_modules] end |
.schema_property_writer_module(schema, conflicting_modules:) ⇒ Object
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 module of writers for described property names of the given schema.
224 225 226 227 |
# File 'lib/jsi/schema_classes.rb', line 224 def schema_property_writer_module(schema, conflicting_modules: ) Schema.ensure_schema(schema) @schema_property_writer_module_map[schema: schema, conflicting_modules: conflicting_modules] end |