class Schematrix::Generators::Templates::Base
Abstract base class for templates
Constants
- CONTAINER_SEGMENTS
-
Namespace segments that come from a container keyword (properties, $defs) rather than a schema that owns its own class file.
Attributes
The merged [type, format] rendering table the type algebra and the coercion plans read. Generators pass the table their scalar_types: option produced; the default is the built in one.
Public Class Methods
# File lib/schematrix/generators/templates/base.rb, line 17 def initialize( module_name:, path:, class_name:, properties:, additional_properties:, documentation_comment:, property_keys: [], scalar_types: Schematrix::BUILTIN_SCALAR_TYPES, enums: :unions, immutable: false, optionals: :nilable, maybe: nil, all_slots_maybe: false, namespace_prefix: nil ) @module_name = module_name @path = path @class_name = class_name @properties = properties @property_keys = property_keys @additional_properties = additional_properties @documentation_comment = documentation_comment @scalar_types = scalar_types @enums = enums @immutable = immutable @optionals = optionals @maybe = maybe @all_slots_maybe = all_slots_maybe @namespace_prefix = namespace_prefix end
Holds everything an ERB template reads: the module namespace, the schema path, the class name, the properties keyed by mangled name, the original-name key map, the catch-all schema, and the description comment.
Public Instance Methods
# File lib/schematrix/generators/templates/base.rb, line 66 def lookup_scalar_type(type, format = nil) scalar_types[[type, format]] || scalar_types[[type, nil]] end
The rendering entry of a [type, format] pair, most specific first: the exact pair, then the bare type. nil when neither is in the table, so an unknown format renders as its bare type and an unknown type as unconstrained.
Source
# File lib/schematrix/generators/templates/base.rb, line 72 def render(erb) erb.result(binding) end
Evaluates the ERB with this template’s binding: the template calls the helper methods below and in the included modules.