Class: Depot::Updater
- Inherits:
-
Object
- Object
- Depot::Updater
- Defined in:
- lib/depot/updater.rb
Class Method Summary collapse
- .set_source(app_id, url) ⇒ Object
- .update(app_id, options = {}) ⇒ Object
- .update_all(options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(store: ManifestStore.new, settings: Settings.new) ⇒ Updater
constructor
A new instance of Updater.
- #records ⇒ Object
- #set_source(app_id, url) ⇒ Object
- #update(app_id, options = {}) ⇒ Object
- #update_all(options = {}) ⇒ Object
Constructor Details
#initialize(store: ManifestStore.new, settings: Settings.new) ⇒ Updater
Returns a new instance of Updater.
27 28 29 30 |
# File 'lib/depot/updater.rb', line 27 def initialize(store: ManifestStore.new, settings: Settings.new) @store = store @settings = settings end |
Class Method Details
.set_source(app_id, url) ⇒ Object
23 24 25 |
# File 'lib/depot/updater.rb', line 23 def self.set_source(app_id, url) new.set_source(app_id, url) end |
.update(app_id, options = {}) ⇒ Object
15 16 17 |
# File 'lib/depot/updater.rb', line 15 def self.update(app_id, = {}) new.update(app_id, ) end |
.update_all(options = {}) ⇒ Object
19 20 21 |
# File 'lib/depot/updater.rb', line 19 def self.update_all( = {}) new.update_all() end |
Instance Method Details
#records ⇒ Object
32 33 34 |
# File 'lib/depot/updater.rb', line 32 def records @store.all.map { |manifest| update_record(manifest) } end |
#set_source(app_id, url) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/depot/updater.rb', line 65 def set_source(app_id, url) manifest = @store.find(app_id) return Result.err("No installed app found for #{app_id}") unless manifest return Result.err("Update URL must use https://.") unless UpdateDownloader.https_url?(url) update = manifest.fetch("update", {}).merge( "source" => url, "mechanism" => "url-download", "status" => "ready", "last_checked_at" => Time.now.utc.iso8601 ) @store.write(manifest.merge("update" => update)) Result.ok(@store.find(app_id)) end |
#update(app_id, options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/depot/updater.rb', line 36 def update(app_id, = {}) return Result.err("Updates are disabled in Depot settings.") unless updates_enabled?() manifest = @store.find(app_id) return Result.err("No installed app found for #{app_id}") unless manifest case manifest.fetch("backend", "") when "flatpak" update_flatpak(manifest) else reinstall_from_source(manifest, ) end end |
#update_all(options = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/depot/updater.rb', line 50 def update_all( = {}) return Result.err("Updates are disabled in Depot settings.") unless updates_enabled?() results = records.map do |record| next { "app_id" => record.fetch("app_id"), "ok" => false, "error" => record.fetch("status") } unless record.fetch("enabled") result = update(record.fetch("app_id"), ) { "app_id" => record.fetch("app_id"), "ok" => result.ok?, "error" => result.error, "value" => result.value } end failed = results.reject { |result| result.fetch("ok") } return Result.err("#{failed.length} updates failed.", warnings: failed.map { |result| "#{result.fetch("app_id")}: #{result.fetch("error")}" }) unless failed.empty? Result.ok({ "updated" => results }) end |