class Mmi::Source::Github
Attributes
asset_id[R]
file[R]
filename[R]
install_dir[R]
options[R]
owner[R]
release[R]
repo[R]
Public Class Methods
new(options)
click to toggle source
# File lib/mmi/source/github.rb, line 15 def initialize(options) @options = options @owner = options['owner' ] @repo = options['repo' ] @asset_id = options['asset_id' ] @release = options['release' ] @file = options['file' ] @install_dir = options['install_dir'] @filename = options['filename' ] if self.owner if self.repo if self.install_dir if self.asset_id # Pass. else if self.release if self.file # Pass. else raise Mmi::MissingAttributeError, 'Missing "source.file" from asset because "source.asset_id" is not provided.' end else raise Mmi::MissingAttributeError, 'Missing "source.release" from asset because "source.asset_id" is not provided.' end end else raise Mmi::MissingAttributeError, 'Missing "source.install_dir" from asset.' end else raise Mmi::MissingAttributeError, 'Missing "source.repo" from asset.' end else raise Mmi::MissingAttributeError, 'Missing "source.owner" from asset.' end end
Public Instance Methods
cached_asset_response()
click to toggle source
# File lib/mmi/source/github.rb, line 57 def cached_asset_response @asset_get ||= ::Github::Client::Repos::Releases::Assets.new.get(owner: self.owner, repo: self.repo, id: self.asset_id) end
display_name()
click to toggle source
# File lib/mmi/source/github.rb, line 86 def display_name repository_url end
download_url()
click to toggle source
# File lib/mmi/source/github.rb, line 61 def download_url if self.asset_id cached_asset_response.browser_download_url else "#{repository_url}/releases/download/#{release}/#{file}" end end
install(dir)
click to toggle source
# File lib/mmi/source/github.rb, line 69 def install(dir) install_dir = File.expand_path(self.install_dir, dir) filepath = File.join(install_dir, self.filename || (self.asset_id ? cached_asset_response.name : self.file)) Mmi.info "Downloading #{download_url.inspect} into #{filepath.inspect}." FileUtils.mkdir_p(install_dir) begin stream = URI.open(download_url) IO.copy_stream(stream, filepath) rescue OpenURI::HTTPError => e Mmi.fail! %Q{Error when requesting asset.\n#{e.inspect}} end end
repository_url()
click to toggle source
# File lib/mmi/source/github.rb, line 53 def repository_url "https://github.com/#{self.owner}/#{self.repo}" end