class Schematrix::Generators::Maybe
Writes the generated Maybe module once per output directory, for every generator the pipeline runs with optionals: :maybe and no supplied maybe module. The flavor follows the generator family: the Sorbet formats get the sealed generic under # typed: strict, the plain formats the same classes without the signatures, and the RBS formats the signatures alone. Like the coercion helper, the file lands next to the class files that reference it, and the generated code depends on nothing but sorbet-runtime in the Sorbet formats.
Public Class Methods
# File lib/schematrix/generators/maybe.rb, line 15 def initialize(output_dir, module_name, flavor:, format:, command: nil) super(output_dir, module_name, format:, command:) @flavor = flavor end
Calls superclass method
Public Instance Methods
Source
# File lib/schematrix/generators/maybe.rb, line 35 def run_once_render { "maybe#{extension}" => rendered_code } end
Source
# File lib/schematrix/generators/maybe.rb, line 23 def run_once_target_paths [File.join(@output_dir, "maybe#{extension}")] end
The static targets the flavor claims, so a schema class folding onto one of them fails the run before any file is written.
Source
# File lib/schematrix/generators/maybe.rb, line 27 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