Module: DesktopDownloader
- Defined in:
- lib/utilities/desktop_downloader.rb
Overview
Downloads the latest Raider Desktop release for the current platform. Uses the GitHub API to discover the latest release and match the right artifact.
Constant Summary collapse
- REPO =
'RaiderHQ/raider_desktop'- API_URL =
"https://api.github.com/repos/#{REPO}/releases/latest".freeze
- PLATFORM_PATTERNS =
{ 'mac_arm' => /\.dmg$/i, 'mac_intel' => /\.dmg$/i, 'windows' => /setup\.exe$/i, 'linux_deb' => /\.deb$/i, 'linux_appimage' => /\.AppImage$/i }.freeze
- HTTP_OPEN_TIMEOUT =
10- HTTP_READ_TIMEOUT =
15
Class Method Summary collapse
-
.clear_cache ⇒ Object
Clear cached release data (useful between operations or for testing).
- .download(destination_dir = nil) ⇒ Object
- .download_url ⇒ Object
- .latest_version ⇒ Object
- .platform ⇒ Object
- .platform_display_name ⇒ Object
Class Method Details
.clear_cache ⇒ Object
Clear cached release data (useful between operations or for testing)
51 52 53 |
# File 'lib/utilities/desktop_downloader.rb', line 51 def clear_cache @cached_release = :unset end |
.download(destination_dir = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/utilities/desktop_downloader.rb', line 26 def download(destination_dir = nil) destination_dir ||= default_download_dir asset = find_asset unless asset warn '[Ruby Raider] No desktop release found for your platform' return nil end destination = File.join(destination_dir, asset[:name]) puts "Downloading Raider Desktop (#{asset[:name]})..." download_file(asset[:url], destination) puts "Downloaded to: #{destination}" destination end |
.download_url ⇒ Object
45 46 47 48 |
# File 'lib/utilities/desktop_downloader.rb', line 45 def download_url asset = find_asset asset&.dig(:url) end |
.latest_version ⇒ Object
41 42 43 |
# File 'lib/utilities/desktop_downloader.rb', line 41 def latest_version cached_release&.dig('tag_name') end |
.platform ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/utilities/desktop_downloader.rb', line 55 def platform host_os = RbConfig::CONFIG['host_os'] arch = RbConfig::CONFIG['host_cpu'] case host_os when /darwin|mac os/i arch =~ /arm|aarch64/i ? 'mac_arm' : 'mac_intel' when /mswin|mingw|cygwin|windows/i 'windows' when /linux/i 'linux_appimage' else 'linux_appimage' end end |
.platform_display_name ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/utilities/desktop_downloader.rb', line 71 def platform_display_name case platform when 'mac_arm' then 'macOS (Apple Silicon)' when 'mac_intel' then 'macOS (Intel)' when 'windows' then 'Windows' when 'linux_deb' then 'Linux (deb)' when 'linux_appimage' then 'Linux (AppImage)' else 'Unknown' end end |