Class: Depot::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/depot/installer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store: ManifestStore.new, settings: Settings.new) ⇒ Installer

Returns a new instance of Installer.



21
22
23
24
# File 'lib/depot/installer.rb', line 21

def initialize(store: ManifestStore.new, settings: Settings.new)
  @store = store
  @settings = settings
end

Class Method Details

.install(input, options = {}) ⇒ Object



17
18
19
# File 'lib/depot/installer.rb', line 17

def self.install(input, options = {})
  new.install(input, options)
end

Instance Method Details

#install(input, options = {}) ⇒ Object



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
52
# File 'lib/depot/installer.rb', line 26

def install(input, options = {})
  inspection_result = Inspector.inspect(input)
  return inspection_result unless inspection_result.ok?

  inspection = inspection_result.value
  merged_settings = @settings.load.merge(options.fetch(:settings, {}))
  result = case inspection.format
           when "appimage"
             Backends::AppImage.new(store: @store).install(inspection, settings: merged_settings)
           when "deb"
             Backends::Deb.new(store: @store).install(inspection, settings: merged_settings)
           when "tar.gz", "tar.xz", "tar.zst"
             Backends::Archive.new(store: @store).install(inspection, settings: merged_settings)
           when "rpm"
             Backends::Rpm.new(store: @store).install(inspection, settings: merged_settings)
           when "flatpakref"
             Backends::FlatpakRefBackend.new(store: @store).install(inspection, settings: merged_settings)
           else
             Result.err("No installer backend is available for detected format: #{inspection.format}")
           end
  return result unless result.ok?

  sandboxed = Sandbox.apply(result.value, settings: merged_settings, store: @store)
  return sandboxed unless sandboxed.ok?

  Result.ok(sandboxed.value, warnings: result.warnings)
end