Class: Castkit::Generators::Base Abstract
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Castkit::Generators::Base
- Includes:
- Thor::Actions
- Defined in:
- lib/generators/base.rb
Overview
Abstract base class for all Castkit generators.
Provides standard behavior for generating a component and optional spec file from ERB templates. Subclasses must define a ‘component` (e.g., `:type`, `:contract`) and may override `config` or `default_values`.
Template variables are injected using the ‘config` hash, which includes:
-
‘:name` – underscored version of the component name
-
‘:class_name` – PascalCase version of the component name
Direct Known Subclasses
Class Method Summary collapse
-
.component(value = nil) ⇒ Symbol
Sets or retrieves the component type (e.g., :type, :data_object).
-
.source_root ⇒ String
The root path to look for templates.
Instance Method Summary collapse
-
#create_component ⇒ void
Creates the main component file using a template.
-
#create_spec ⇒ void
Creates the associated spec file, if enabled.
Class Method Details
.component(value = nil) ⇒ Symbol
Sets or retrieves the component type (e.g., :type, :data_object).
27 28 29 |
# File 'lib/generators/base.rb', line 27 def component(value = nil) value.nil? ? @component : (@component = value) end |
.source_root ⇒ String
Returns the root path to look for templates.
32 33 34 |
# File 'lib/generators/base.rb', line 32 def source_root File.("templates", __dir__) end |
Instance Method Details
#create_component ⇒ void
This method returns an undefined value.
Creates the main component file using a template.
Template: ‘component.rb.tt` Target: `lib/castkit/#components/#name.rb`
46 47 48 49 50 51 |
# File 'lib/generators/base.rb', line 46 def create_component template( "#{self.class.component}.rb.tt", "lib/castkit/#{self.class.component}s/#{config[:name]}.rb", **config ) end |
#create_spec ⇒ void
This method returns an undefined value.
Creates the associated spec file, if enabled.
Template: ‘component_spec.rb.tt` Target: `spec/castkit/#components/#name_spec.rb`
59 60 61 62 63 64 65 66 |
# File 'lib/generators/base.rb', line 59 def create_spec return unless [:spec] template( "#{self.class.component}_spec.rb.tt", "spec/castkit/#{self.class.component}s/#{config[:name]}_spec.rb", **config ) end |