debian-mirror-gitlab/lib/gitlab_edition.rb

72 lines
1.6 KiB
Ruby
Raw Normal View History

2022-03-02 08:16:31 +05:30
# frozen_string_literal: true
require 'pathname'
module GitlabEdition
def self.root
Pathname.new(File.expand_path('..', __dir__))
end
2022-10-11 01:57:18 +05:30
def self.path_glob(path)
"#{root}/#{extension_path_prefixes}#{path}"
end
def self.extension_path_prefixes
path_prefixes = extensions
return '' if path_prefixes.empty?
path_prefixes.map! { "#{_1}/" }
path_prefixes.unshift ''
# For example `{,ee/,jh/}`
"{#{path_prefixes.join(',')}}"
end
2022-03-02 08:16:31 +05:30
def self.extensions
if jh?
%w[ee jh]
elsif ee?
%w[ee]
else
%w[]
end
end
def self.ee?
2022-04-04 11:22:00 +05:30
# To reduce dependencies in QA image we are not using
# `Gitlab::Utils::StrongMemoize` but reimplementing its functionality.
return @is_ee if defined?(@is_ee)
@is_ee =
2022-03-02 08:16:31 +05:30
# We use this method when the Rails environment is not loaded. This
# means that checking the presence of the License class could result in
# this method returning `false`, even for an EE installation.
#
# The `FOSS_ONLY` is always `string` or `nil`
# Thus the nil or empty string will result
# in using default value: false
#
# The behavior needs to be synchronised with
# config/helpers/is_ee_env.js
root.join('ee/app/models/license.rb').exist? &&
2023-03-04 22:38:38 +05:30
!%w[true 1].include?(ENV['FOSS_ONLY'].to_s) # rubocop:disable Rails/NegateInclude
2022-03-02 08:16:31 +05:30
end
def self.jh?
2022-04-04 11:22:00 +05:30
return @is_jh if defined?(@is_jh)
@is_jh =
2022-03-02 08:16:31 +05:30
ee? &&
2023-03-04 22:38:38 +05:30
root.join('jh').exist? &&
!%w[true 1].include?(ENV['EE_ONLY'].to_s) # rubocop:disable Rails/NegateInclude
2022-03-02 08:16:31 +05:30
end
def self.ee
yield if ee?
end
def self.jh
yield if jh?
end
end