2023-09-01 17:47:07 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: software_updates
|
|
|
|
#
|
|
|
|
# id :bigint(8) not null, primary key
|
|
|
|
# version :string not null
|
|
|
|
# urgent :boolean default(FALSE), not null
|
|
|
|
# type :integer default("patch"), not null
|
|
|
|
# release_notes :string default(""), not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
#
|
|
|
|
|
|
|
|
class SoftwareUpdate < ApplicationRecord
|
|
|
|
self.inheritance_column = nil
|
|
|
|
|
2024-02-16 15:54:23 +01:00
|
|
|
enum :type, { patch: 0, minor: 1, major: 2 }, suffix: :type
|
2023-09-01 17:47:07 +02:00
|
|
|
|
|
|
|
def gem_version
|
|
|
|
Gem::Version.new(version)
|
|
|
|
end
|
|
|
|
|
2024-11-14 15:03:57 +01:00
|
|
|
def outdated?
|
|
|
|
runtime_version >= gem_version
|
|
|
|
end
|
|
|
|
|
|
|
|
def pending?
|
|
|
|
gem_version > runtime_version
|
|
|
|
end
|
|
|
|
|
2023-09-01 17:47:07 +02:00
|
|
|
class << self
|
|
|
|
def check_enabled?
|
2024-11-12 09:28:31 +01:00
|
|
|
Rails.configuration.x.mastodon.software_update_url.present?
|
2023-09-01 17:47:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def pending_to_a
|
|
|
|
return [] unless check_enabled?
|
|
|
|
|
2024-11-14 15:03:57 +01:00
|
|
|
all.to_a.filter(&:pending?)
|
2023-09-01 17:47:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def urgent_pending?
|
|
|
|
pending_to_a.any?(&:urgent?)
|
|
|
|
end
|
|
|
|
end
|
2024-11-14 15:03:57 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def runtime_version
|
|
|
|
Mastodon::Version.gem_version
|
|
|
|
end
|
2023-09-01 17:47:07 +02:00
|
|
|
end
|