Class: RosettAi::Project::TemplateApplier
- Inherits:
-
Object
- Object
- RosettAi::Project::TemplateApplier
- Defined in:
- lib/rosett_ai/project/template_applier.rb
Overview
Applies project templates to populate .rosett-ai/ with starter configs.
Templates are directories under conf/templates/ containing behaviour and design YAML files. Application never overwrites user-modified files without explicit --force flag.
Constant Summary collapse
- TEMPLATES_DIR =
'conf/templates'
Class Method Summary collapse
-
.available_templates ⇒ Array<String>
List of available template names.
Instance Method Summary collapse
-
#apply ⇒ Hash
Applies the template to the project.
-
#initialize(project_root:, template_name:, force: false) ⇒ TemplateApplier
constructor
A new instance of TemplateApplier.
-
#template_exists? ⇒ Boolean
True if the template exists.
Constructor Details
#initialize(project_root:, template_name:, force: false) ⇒ TemplateApplier
Returns a new instance of TemplateApplier.
25 26 27 28 29 30 |
# File 'lib/rosett_ai/project/template_applier.rb', line 25 def initialize(project_root:, template_name:, force: false) @project_root = project_root @template_name = template_name @force = force @project_dir = project_root.join('.rosett-ai') end |
Class Method Details
.available_templates ⇒ Array<String>
Returns list of available template names.
55 56 57 58 59 60 61 62 |
# File 'lib/rosett_ai/project/template_applier.rb', line 55 def self.available_templates dir = RosettAi.root.join(TEMPLATES_DIR) return [] unless dir.directory? Dir.children(dir.to_s) .select { |name| dir.join(name).directory? } .sort end |
Instance Method Details
#apply ⇒ Hash
Applies the template to the project.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rosett_ai/project/template_applier.rb', line 35 def apply validate! results = { applied: [], skipped: [], errors: [] } template_files.each do |src_path| relative = src_path.relative_path_from(template_dir) dest = @project_dir.join(relative) apply_file(src_path, dest, results) end record_template_origin results end |
#template_exists? ⇒ Boolean
Returns true if the template exists.
50 51 52 |
# File 'lib/rosett_ai/project/template_applier.rb', line 50 def template_exists? template_dir.directory? end |