Class: Mmi::Source::Github
- Inherits:
-
Object
- Object
- Mmi::Source::Github
- Defined in:
- lib/mmi/source/github.rb
Instance Attribute Summary collapse
-
#asset_id ⇒ Object
readonly
Returns the value of attribute asset_id.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#install_dir ⇒ Object
readonly
Returns the value of attribute install_dir.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#release ⇒ Object
readonly
Returns the value of attribute release.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
- #cached_asset_response ⇒ Object
- #display_name ⇒ Object
- #download_url ⇒ Object
-
#initialize(options) ⇒ Github
constructor
A new instance of Github.
- #install(dir) ⇒ Object
- #repository_url ⇒ Object
Constructor Details
#initialize(options) ⇒ Github
Returns a new instance of Github.
15 16 17 18 19 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 45 46 47 48 49 50 51 |
# File 'lib/mmi/source/github.rb', line 15 def initialize() @options = @owner = ['owner' ] @repo = ['repo' ] @asset_id = ['asset_id' ] @release = ['release' ] @file = ['file' ] @install_dir = ['install_dir'] @filename = ['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 |
Instance Attribute Details
#asset_id ⇒ Object (readonly)
Returns the value of attribute asset_id.
11 12 13 |
# File 'lib/mmi/source/github.rb', line 11 def asset_id @asset_id end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
13 14 15 |
# File 'lib/mmi/source/github.rb', line 13 def file @file end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
9 10 11 |
# File 'lib/mmi/source/github.rb', line 9 def filename @filename end |
#install_dir ⇒ Object (readonly)
Returns the value of attribute install_dir.
8 9 10 |
# File 'lib/mmi/source/github.rb', line 8 def install_dir @install_dir end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/mmi/source/github.rb', line 4 def @options end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
6 7 8 |
# File 'lib/mmi/source/github.rb', line 6 def owner @owner end |
#release ⇒ Object (readonly)
Returns the value of attribute release.
12 13 14 |
# File 'lib/mmi/source/github.rb', line 12 def release @release end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
7 8 9 |
# File 'lib/mmi/source/github.rb', line 7 def repo @repo end |
Instance Method Details
#cached_asset_response ⇒ Object
57 58 59 |
# 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 ⇒ Object
86 87 88 |
# File 'lib/mmi/source/github.rb', line 86 def display_name repository_url end |
#download_url ⇒ Object
61 62 63 64 65 66 67 |
# 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) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mmi/source/github.rb', line 69 def install(dir) install_dir = File.(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 ⇒ Object
53 54 55 |
# File 'lib/mmi/source/github.rb', line 53 def repository_url "https://github.com/#{self.owner}/#{self.repo}" end |