1
0

software_update.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: software_updates
  5. #
  6. # id :bigint(8) not null, primary key
  7. # version :string not null
  8. # urgent :boolean default(FALSE), not null
  9. # type :integer default("patch"), not null
  10. # release_notes :string default(""), not null
  11. # created_at :datetime not null
  12. # updated_at :datetime not null
  13. #
  14. class SoftwareUpdate < ApplicationRecord
  15. self.inheritance_column = nil
  16. enum :type, { patch: 0, minor: 1, major: 2 }, suffix: :type
  17. def gem_version
  18. Gem::Version.new(version)
  19. end
  20. def outdated?
  21. runtime_version >= gem_version
  22. end
  23. def pending?
  24. gem_version > runtime_version
  25. end
  26. class << self
  27. def check_enabled?
  28. Rails.configuration.x.mastodon.software_update_url.present?
  29. end
  30. def pending_to_a
  31. return [] unless check_enabled?
  32. all.to_a.filter(&:pending?)
  33. end
  34. def urgent_pending?
  35. pending_to_a.any?(&:urgent?)
  36. end
  37. end
  38. private
  39. def runtime_version
  40. Mastodon::Version.gem_version
  41. end
  42. end