software_update.rb 969 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. class << self
  21. def check_enabled?
  22. ENV['UPDATE_CHECK_URL'] != ''
  23. end
  24. def pending_to_a
  25. return [] unless check_enabled?
  26. all.to_a.filter { |update| update.gem_version > Mastodon::Version.gem_version }
  27. end
  28. def urgent_pending?
  29. pending_to_a.any?(&:urgent?)
  30. end
  31. end
  32. end