Class: Mmi::Source::Github

Inherits:
Object
  • Object
show all
Includes:
PropertyAttributes
Defined in:
lib/mmi/source/github.rb

Instance Method Summary collapse

Methods included from PropertyAttributes

#[], #initialize, #parse!, #parsed_property_store, prepended, #to_h, #update_properties!, #validate_constraints!

Instance Method Details

#cached_asset_responseObject



27
28
29
# File 'lib/mmi/source/github.rb', line 27

def cached_asset_response
	@cached_asset_response ||= Mmi::GithubApi.client.release_asset("/repos/#{self.owner}/#{self.repo}/releases/assets/#{self.asset_id}")
end

#display_nameObject



45
46
47
# File 'lib/mmi/source/github.rb', line 45

def display_name
	repository_url
end

#download_urlObject



31
32
33
34
35
36
37
# File 'lib/mmi/source/github.rb', line 31

def download_url
	if self.asset_id
		cached_asset_response.browser_download_url
	else
		"#{repository_url}/releases/download/#{release}/#{file}"
	end
end

#install(install_record) ⇒ Object



39
40
41
42
43
# File 'lib/mmi/source/github.rb', line 39

def install(install_record)
	filepath = File.join(install_dir, self.filename || (self.asset_id ? cached_asset_response.name : self.file))
	
	install_record.add(download_url, filepath, content_hash: nil) # As of 2024-07-18, the GitHub API does not return any hash over the asset.
end

#repository_urlObject

TODO: Ensure that either :asset_id or [:release, :file] is given.



23
24
25
# File 'lib/mmi/source/github.rb', line 23

def repository_url
	"https://github.com/#{self.owner}/#{self.repo}"
end