Class: RosettAi::Project::TemplateApplier

Inherits:
Object
  • Object
show all
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.

Author:

  • hugo

  • claude

Constant Summary collapse

TEMPLATES_DIR =
'conf/templates'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_root:, template_name:, force: false) ⇒ TemplateApplier

Returns a new instance of TemplateApplier.

Parameters:

  • project_root (Pathname)

    root directory of the project

  • template_name (String)

    name of the template to apply

  • force (Boolean) (defaults to: false)

    overwrite existing files



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_templatesArray<String>

Returns list of available template names.

Returns:

  • (Array<String>)

    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

#applyHash

Applies the template to the project.

Returns:

  • (Hash)

    result with :applied, :skipped, :errors arrays



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.

Returns:

  • (Boolean)

    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