Class: Generamba::CatalogDownloader
- Inherits:
-
Object
- Object
- Generamba::CatalogDownloader
- Defined in:
- lib/generamba/template/helpers/catalog_downloader.rb
Overview
Provides the functionality to download template catalogs from the remote repository
Instance Method Summary collapse
-
#download_catalog(name, url) ⇒ Pathname
Clones a template catalog from a remote repository.
-
#update_all_catalogs_and_return_filepaths ⇒ Array
Updates all of the template catalogs and returns their filepaths.
Instance Method Details
#download_catalog(name, url) ⇒ Pathname
Clones a template catalog from a remote repository
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/generamba/template/helpers/catalog_downloader.rb', line 41 def download_catalog(name, url) catalogs_local_path = Pathname.new(ENV['HOME']) .join(GENERAMBA_HOME_DIR) .join(CATALOGS_DIR) current_catalog_path = catalogs_local_path .join(name) if File.exists?(current_catalog_path) g = Git.open(current_catalog_path) g.pull else Git.clone(url, name, :path => catalogs_local_path) end return current_catalog_path end |
#update_all_catalogs_and_return_filepaths ⇒ Array
Updates all of the template catalogs and returns their filepaths. If there is a Rambafile in the current directory, it also updates all of the catalogs specified there.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/generamba/template/helpers/catalog_downloader.rb', line 12 def update_all_catalogs_and_return_filepaths does_rambafile_exist = Dir[RAMBAFILE_NAME].count > 0 if does_rambafile_exist rambafile = YAML.load_file(RAMBAFILE_NAME) catalogs = rambafile[CATALOGS_KEY] end terminator = CatalogTerminator.new terminator.remove_all_catalogs catalog_paths = [download_catalog(GENERAMBA_CATALOG_NAME, RAMBLER_CATALOG_REPO)] if catalogs != nil && catalogs.count > 0 catalogs.each do |catalog_url| catalog_name = catalog_url.split('://').last catalog_name = catalog_name.gsub('/', '-'); catalog_paths.push(download_catalog(catalog_name, catalog_url)) end end return catalog_paths end |