Class: Viperaptor::CatalogDownloader
- Inherits:
-
Object
- Object
- Viperaptor::CatalogDownloader
- Defined in:
- lib/viperaptor/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.
- #external_catalogs_filepaths ⇒ Object
-
#update_all_catalogs_and_return_filepaths(throttled = false) ⇒ 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
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/viperaptor/template/helpers/catalog_downloader.rb', line 83 def download_catalog(name, url) catalogs_local_path = Pathname.new(ENV['HOME']) .join(APP_HOME_DIR) .join(CATALOGS_DIR) current_catalog_path = catalogs_local_path .join(name) puts("Updating #{name} specs (#{url})...") git_dir = current_catalog_path.join('.git') if File.directory?(git_dir) g = Git.open(current_catalog_path) g.pull FileUtils.touch current_catalog_path else FileUtils.rm_rf current_catalog_path Git.clone(url, name, :path => catalogs_local_path) end return current_catalog_path end |
#external_catalogs_filepaths ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/viperaptor/template/helpers/catalog_downloader.rb', line 9 def external_catalogs_filepaths catalogs_path = Pathname.new(ENV['HOME']) .join(APP_HOME_DIR) .join(CATALOGS_DIR) return [] unless catalogs_path.exist? catalogs_path.children.select { |child| child.directory? && child.split.last.to_s[0] != '.' } end |
#update_all_catalogs_and_return_filepaths(throttled = false) ⇒ 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.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/viperaptor/template/helpers/catalog_downloader.rb', line 26 def update_all_catalogs_and_return_filepaths(throttled = false) does_rambafile_exist = Rambafile.exist if does_rambafile_exist rambafile = Rambafile.rambafile catalogs = rambafile[CATALOGS_KEY] end # terminator = CatalogTerminator.new # terminator.remove_all_catalogs repos = (Viperaptor::UserPreferences.obtain_custom_catalogs_repos || []) + PREDEFINED_CATALOG_REPOS catalog_paths = repos.map do |repo| name = repo.split('/').last catalogs_local_path = Pathname.new(ENV['HOME']) .join(APP_HOME_DIR) .join(CATALOGS_DIR) current_catalog_path = catalogs_local_path .join(name) if !current_catalog_path.exist? || !throttled || (Time.now - current_catalog_path.mtime) > 3600.0 * 12.0 download_catalog(name, repo) end current_catalog_path end if catalogs != nil && catalogs.count > 0 catalogs.each do |catalog_url| name = catalog_url.split('://').last name = name.gsub('/', '-'); catalogs_local_path = Pathname.new(ENV['HOME']) .join(APP_HOME_DIR) .join(CATALOGS_DIR) current_catalog_path = catalogs_local_path .join(name) if !current_catalog_path.exist? || !throttled || (Time.now - current_catalog_path.mtime) > 3600.0 * 12.0 download_catalog(name, catalog_url) end catalog_paths.push(current_catalog_path) end end return catalog_paths end |