Class: Mxrb::OfficialMarketplace::WidgetPackageInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/official_marketplace/widget_package_installer.rb

Overview

Installs an already authenticated official widget archive as one project-owned MPK. rubocop:disable Metrics

Instance Method Summary collapse

Constructor Details

#initialize(target:) ⇒ WidgetPackageInstaller

Returns a new instance of WidgetPackageInstaller.



198
199
200
# File 'lib/mxrb/official_marketplace/widget_package_installer.rb', line 198

def initialize(target:)
  @target = File.expand_path(target)
end

Instance Method Details

#install(archive, package) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/mxrb/official_marketplace/widget_package_installer.rb', line 202

def install(archive, package)
  Progress.with("Installing widget #{package.name}") do |progress|
    validate_target!
    progress.update(detail: 'reading widget package')
    inventory = WidgetPackageInventory.read(archive)
    validate_identity!(inventory, package)
    digest = Digest::SHA256.file(archive).hexdigest
    destination = safe_path(File.join('widgets', inventory.project_filename))
    cache = safe_path(cache_relative(inventory, package))
    lock_path = safe_path(File.join('.mxrb', 'marketplace.lock.json'))
    current = validate_boundaries!(package, destination, cache, lock_path)
    progress.update(detail: 'installing project assets')
    install_transaction(
      archive, package, inventory, digest, destination, cache, lock_path, current
    )
  end
end