Class: Generamba::TemplateProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/generamba/template/processor/template_processor.rb

Overview

Incapsulates logic of processing templates declaration section from Rambafile

Instance Method Summary collapse

Constructor Details

#initialize(catalog_downloader, installer_factory) ⇒ TemplateProcessor

Returns a new instance of TemplateProcessor.



14
15
16
17
# File 'lib/generamba/template/processor/template_processor.rb', line 14

def initialize(catalog_downloader, installer_factory)
  @catalog_downloader = catalog_downloader
  @installer_factory = installer_factory
end

Instance Method Details

#install_templates(rambafile) ⇒ Object

This method parses Rambafile, serializes templates hashes into model objects and install them



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generamba/template/processor/template_processor.rb', line 20

def install_templates(rambafile)
  # We always clear previously installed templates to avoid conflicts in different versions
  clear_installed_templates

  templates = rambafile[TEMPLATES_KEY]

  if !templates || templates.count == 0
    puts 'You must specify at least one template in Rambafile under the key *templates*'.red
    return
  end

  # Mapping hashes to model objects
  templates = rambafile[TEMPLATES_KEY].map { |template_hash|
    Generamba::TemplateDeclaration.new(template_hash)
  }

  catalogs = rambafile[CATALOGS_KEY]
  # If there is at least one template from catalogs, we should update our local copy of the catalog
  update_catalogs_if_needed(catalogs, templates)

  templates.each do |template_declaration|
    strategy = @installer_factory.installer_for_type(template_declaration.type)
    template_declaration.install(strategy)
  end
end