class Generamba::TemplateProcessor
Incapsulates logic of processing templates declaration section from Rambafile
Public Class Methods
new(catalog_downloader, installer_factory)
click to toggle source
# 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
Public Instance Methods
install_templates(rambafile)
click to toggle source
This method parses Rambafile, serializes templates hashes into model objects and install them
# 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
Private Instance Methods
clear_installed_templates()
click to toggle source
Clears all of the currently installed templates
# File lib/generamba/template/processor/template_processor.rb, line 49 def clear_installed_templates install_path = Pathname.new(TEMPLATES_FOLDER) FileUtils.rm_rf(Dir.glob(install_path)) end
update_catalogs_if_needed(catalogs, templates)
click to toggle source
Clones remote template catalogs to the local directory
# File lib/generamba/template/processor/template_processor.rb, line 55 def update_catalogs_if_needed(catalogs, templates) needs_update = templates.any? {|template| template.type == TemplateDeclarationType::CATALOG_TEMPLATE} return unless needs_update terminator = CatalogTerminator.new terminator.remove_all_catalogs puts('Updating shared generamba-catalog specs...') @catalog_downloader.download_catalog(GENERAMBA_CATALOG_NAME, RAMBLER_CATALOG_REPO) return unless catalogs != nil && catalogs.count > 0 catalogs.each do |catalog_url| catalog_name = catalog_url.split('://').last catalog_name = catalog_name.gsub('/', '-'); puts("Updating #{catalog_name} specs...") @catalog_downloader.download_catalog(catalog_name, catalog_url) end end