Class: Generamba::LocalInstaller

Inherits:
AbstractInstaller show all
Defined in:
lib/generamba/template/installer/local_installer.rb

Overview

Incapsulates the logic of verifying and installing local templates

Instance Method Summary collapse

Instance Method Details

#install_template(template_declaration) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/generamba/template/installer/local_installer.rb', line 8

def install_template(template_declaration)
  template_name = template_declaration.name
  puts("Installing #{template_name}...")

  local_path = template_declaration.local
  rambaspec_exist = Generamba::RambaspecValidator.validate_spec_existance(template_name, local_path)

  unless rambaspec_exist
    error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the specified directory. Try another path or name.".red
    raise StandardError.new(error_description)
  end

  rambaspec_valid = Generamba::RambaspecValidator.validate_spec(template_name, local_path)
  unless rambaspec_valid
    error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid.".red
    raise StandardError.new(error_description)
  end

  install_path = Pathname.new(TEMPLATES_FOLDER)
                     .join(template_name)
  FileUtils.mkdir_p install_path
  FileUtils.copy_entry(local_path, install_path)
end