Class: WGPU::Native::Installer
- Inherits:
-
Object
- Object
- WGPU::Native::Installer
- Defined in:
- lib/wgpu/native/installer.rb
Overview
Downloads, verifies, and installs the pinned wgpu-native artifact.
Instance Attribute Summary collapse
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
Instance Method Summary collapse
-
#clean_path ⇒ String
Returns the primary versioned cache directory.
-
#initialize(platform: RUBY_PLATFORM, env: ENV, home: Dir.home, host_os: RbConfig::CONFIG["host_os"], output: $stdout, command_runner: nil, http_factory: nil, zip_file_loader: nil, distribution: Distribution) ⇒ Installer
constructor
Creates an installer for a target Ruby platform.
-
#install ⇒ String
Installs or reuses the native library for #platform.
Constructor Details
#initialize(platform: RUBY_PLATFORM, env: ENV, home: Dir.home, host_os: RbConfig::CONFIG["host_os"], output: $stdout, command_runner: nil, http_factory: nil, zip_file_loader: nil, distribution: Distribution) ⇒ Installer
Creates an installer for a target Ruby platform.
The final four dependencies are injectable to keep network, process, archive, and distribution branches testable without external effects.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/wgpu/native/installer.rb', line 32 def initialize(platform: RUBY_PLATFORM, env: ENV, home: Dir.home, host_os: RbConfig::CONFIG["host_os"], output: $stdout, command_runner: nil, http_factory: nil, zip_file_loader: nil, distribution: Distribution) @platform = platform @env = env @home = home @host_os = host_os @output = output @command_runner = command_runner || method(:system) @http_factory = http_factory || ->(uri) { Net::HTTP.new(uri.host, uri.port) } @zip_file_loader = zip_file_loader || lambda { require "zip" Zip::File } @distribution = distribution end |
Instance Attribute Details
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
16 17 18 |
# File 'lib/wgpu/native/installer.rb', line 16 def platform @platform end |
Instance Method Details
#clean_path ⇒ String
Returns the primary versioned cache directory.
72 73 74 |
# File 'lib/wgpu/native/installer.rb', line 72 def clean_path @distribution.primary_cache_dir(env: @env, home: @home, host_os: @host_os) end |
#install ⇒ String
Installs or reuses the native library for #platform.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/wgpu/native/installer.rb', line 54 def install return custom_library_path if custom_library_path artifact = @distribution.artifact_for(platform) cached_path = existing_library_path(artifact) if cached_path @output.puts "wgpu-native already cached at #{cached_path}" return cached_path end install_artifact(artifact) rescue LoadError, InstallError => error raise InstallError, "#{error.}\n\n#{recovery_instructions}" end |