version.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # frozen_string_literal: true
  2. module Mastodon
  3. module Version
  4. module_function
  5. def major
  6. 4
  7. end
  8. def minor
  9. 3
  10. end
  11. def patch
  12. 0
  13. end
  14. def default_prerelease
  15. 'alpha.1'
  16. end
  17. def prerelease
  18. ENV['MASTODON_VERSION_PRERELEASE'].presence || default_prerelease
  19. end
  20. def build_metadata
  21. ENV.fetch('MASTODON_VERSION_METADATA', nil)
  22. end
  23. def to_a
  24. [major, minor, patch].compact
  25. end
  26. def to_s
  27. components = [to_a.join('.')]
  28. components << "-#{prerelease}" if prerelease.present?
  29. components << "+#{build_metadata}" if build_metadata.present?
  30. components.join
  31. end
  32. def gem_version
  33. @gem_version ||= Gem::Version.new(to_s.split('+')[0])
  34. end
  35. def repository
  36. ENV.fetch('GITHUB_REPOSITORY', 'mastodon/mastodon')
  37. end
  38. def source_base_url
  39. ENV.fetch('SOURCE_BASE_URL', "https://github.com/#{repository}")
  40. end
  41. # specify git tag or commit hash here
  42. def source_tag
  43. ENV.fetch('SOURCE_TAG', nil)
  44. end
  45. def source_url
  46. if source_tag
  47. "#{source_base_url}/tree/#{source_tag}"
  48. else
  49. source_base_url
  50. end
  51. end
  52. def user_agent
  53. @user_agent ||= "#{HTTP::Request::USER_AGENT} (Mastodon/#{Version}; +http#{Rails.configuration.x.use_https ? 's' : ''}://#{Rails.configuration.x.web_domain}/)"
  54. end
  55. end
  56. end