class Schematrix::Generators::AuxiliaryFiles
Writes the shared coercion helper module once per output directory: the built-in coercers under Coercers, the coerce_class_slot dispatcher and the coerce_spec interpreter that generated classes call through qualified names. A run-once generator: the pipeline hands it the whole compiled record set instead of one locator at a time, and the files land next to the class files that require_relative them.
Public Class Methods
Source
# File lib/schematrix/generators/auxiliary_files.rb, line 15 def self.file_extension = ".rb"
Source
# File lib/schematrix/generators/auxiliary_files.rb, line 13 def self.immutable_supported? = false
Source
# File lib/schematrix/generators/auxiliary_files.rb, line 11 def self.run_once? = true
Public Instance Methods
Source
# File lib/schematrix/generators/auxiliary_files.rb, line 41 def run_once_render { "coercion_helper.rb" => with_banner(format_code(ruby_code), "CoercionHelper", "module"), "coercion_helper.rbs" => with_banner(rbs_code, "CoercionHelper", "module"), } end
The rendered, formatted helper files, for callers that want the content without writing it.
Source
# File lib/schematrix/generators/auxiliary_files.rb, line 20 def run_once_target_paths [ File.join(@output_dir, "coercion_helper.rb"), File.join(@output_dir, "coercion_helper.rbs"), ] end
The static targets the generator claims up front, so a schema class folding onto one of them fails the run before any file is written.
Source
# File lib/schematrix/generators/auxiliary_files.rb, line 31 def write_run_once(_objects) FileUtils.mkdir_p(@output_dir) run_once_render.each do |filename, code| File.write(File.join(@output_dir, filename), code) end run_once_target_paths.first end
Renders and writes the helper files. The content is the same for every run: the helpers carry no per-class state, the spec literal travels with each delegation, and every built-in coercer is emitted whether or not a class in the run calls it.