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

Class Method Details

.accessor_module_for_schema(schema, conflicting_modules:, setters: true) ⇒ Object

Deprecated.

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

Parameters:

  • modules (Set<Module>)

    schema implementation modules

Returns:

  • (Class)


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.

Parameters:

  • schemas (Enumerable<JSI::Schema>)

    schemas which the class will represent

  • includes (Enumerable<Module>)

    modules which will be included on the class

Returns:



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.

Returns:

  • (Set<Module>)


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.

see JSI::Schema#jsi_schema_module

Returns:

Raises:



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.

Parameters:

  • schema (JSI::Schema)

    a schema for which to define readers for any described property names

  • conflicting_modules (Enumerable<Module>)

    an array of modules (or classes) which may be used alongside the accessor module. methods defined by any conflicting_module will not be defined as accessors.

Returns:

  • (Module)


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