Class: Mmi::Source::Modrinth

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

Instance Method Summary collapse

Methods included from PropertyAttributes

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

Instance Method Details

#api_version_fileObject



23
24
25
26
27
28
29
30
31
# File 'lib/mmi/source/modrinth.rb', line 23

def api_version_file
	cached_mod_versions.select do |version|
		version['name'] == self.version
	end.map do |version|
		version['files']
	end.flatten(1).select do |files|
		files['filename'] == self.version_file
	end.first
end

#cached_mod_versions(loader: nil, game_version: nil) ⇒ Object



19
20
21
# File 'lib/mmi/source/modrinth.rb', line 19

def cached_mod_versions(loader: nil, game_version: nil)
	(@cached_mod_versions ||= {})[{loader: loader, game_version: game_version}] ||= Mmi::ModrinthApi.project_versions(self.name, loader: loader, game_version: game_version)
end

#display_nameObject



43
44
45
# File 'lib/mmi/source/modrinth.rb', line 43

def display_name
	"https://modrinth.com/mod/#{name}"
end

#download_urlObject



33
34
35
# File 'lib/mmi/source/modrinth.rb', line 33

def download_url
	api_version_file['url'].gsub(/ /, '%20')
end

#install(install_record) ⇒ Object



37
38
39
40
41
# File 'lib/mmi/source/modrinth.rb', line 37

def install(install_record)
	filepath = File.join(install_dir, self.filename || self.version_file)
	
	install_record.add(download_url, filepath, content_hash: Mmi::ContentHash::Sha512.new(api_version_file['hashes']['sha512']))
end