Class: Seams::Generators::FollowUpGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Seams::Generators::FollowUpGenerator
- Defined in:
- lib/seams/generators/follow_up_generator.rb
Overview
Base class for follow-up generators — net-new generators that extend an already-installed engine without re-templating the whole engine. Subclasses look like:
module Seams
module Generators
class AddPasskeysGenerator < FollowUpGenerator
engine_name "auth"
def add_event
splice(
file: "lib/auth/engine.rb",
marker: "auth.engine.events",
content: <<~RUBY
Seams::EventRegistry.register("identity.passkey_added.auth", emitted_by: "Auth")
RUBY
)
end
end
end
end
The base class supplies four primitives that every follow-up generator needs:
-
engine_path(relative) — resolve a path inside the host’s ‘engines/<this_engine>/` directory.
-
splice(file:, marker:, content:, …) — wrap
Splicer.splice_after_markerwith a concise log line. -
assert_marker_exists!(file:, marker:) — fail fast with a clear “this engine wasn’t generated” message when a follow-up generator runs against a host that hasn’t installed the target engine.
-
report_summary— template method subclasses override to print a “what just changed” message at the end.
Direct Known Subclasses
Class Method Summary collapse
-
.engine_name(name = nil) ⇒ Object
Sets the engine this follow-up generator targets.
Class Method Details
.engine_name(name = nil) ⇒ Object
Sets the engine this follow-up generator targets. Used by engine_path to resolve relative paths and by assert_marker_exists! to build the recovery hint.
48 49 50 51 52 53 54 |
# File 'lib/seams/generators/follow_up_generator.rb', line 48 def engine_name(name = nil) @engine_name = name if name @engine_name || raise(ArgumentError, "#{self.name} must declare `engine_name \"<engine>\"` " \ "(e.g. \"auth\") — the base class needs it to resolve " \ "engines/<engine>/ paths.") end |