Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/application.rb10
-rw-r--r--config/initializers/0_inject_com_module.rb26
-rw-r--r--config/light_settings.rb32
3 files changed, 68 insertions, 0 deletions
diff --git a/config/application.rb b/config/application.rb
index 5d7c52c5d81..192e836594a 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -22,6 +22,7 @@ module Gitlab
require_dependency Rails.root.join('lib/gitlab/current_settings')
require_dependency Rails.root.join('lib/gitlab/middleware/read_only')
require_dependency Rails.root.join('lib/gitlab/middleware/basic_health_check')
+ require_dependency Rails.root.join('config/light_settings')
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
@@ -62,6 +63,15 @@ module Gitlab
config.paths['app/views'].unshift "#{config.root}/ee/app/views"
end
+ if LightSettings.com?
+ com_paths = config.eager_load_paths.each_with_object([]) do |path, memo|
+ com_path = config.root.join('com', Pathname.new(path).relative_path_from(config.root))
+ memo << com_path.to_s
+ end
+
+ config.eager_load_paths.push(*com_paths)
+ end
+
# Rake tasks ignore the eager loading settings, so we need to set the
# autoload paths explicitly
config.autoload_paths = config.eager_load_paths.dup
diff --git a/config/initializers/0_inject_com_module.rb b/config/initializers/0_inject_com_module.rb
new file mode 100644
index 00000000000..9802eb37ec3
--- /dev/null
+++ b/config/initializers/0_inject_com_module.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+require 'active_support/inflector'
+
+module InjectComModule
+ def prepend_if_com(constant, with_descendants: false)
+ return unless Gitlab.com?
+
+ com_module = constant.constantize
+ prepend(com_module)
+
+ if with_descendants
+ descendants.each { |descendant| descendant.prepend(com_module) }
+ end
+ end
+
+ def extend_if_com(constant)
+ extend(constant.constantize) if Gitlab.com?
+ end
+
+ def include_if_com(constant)
+ include(constant.constantize) if Gitlab.com?
+ end
+end
+
+Module.prepend(InjectComModule)
diff --git a/config/light_settings.rb b/config/light_settings.rb
new file mode 100644
index 00000000000..aa0dd04b3fa
--- /dev/null
+++ b/config/light_settings.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+class LightSettings
+ GL_HOST ||= 'gitlab.com'
+ GL_SUBDOMAIN_REGEX ||= %r{\A[a-z0-9]+\.gitlab\.com\z}.freeze
+
+ class << self
+ def com?
+ return Thread.current[:is_com] unless Thread.current[:is_com].nil?
+
+ Thread.current[:is_com] = host == GL_HOST || gl_subdomain?
+ end
+
+ private
+
+ def config
+ YAML.safe_load(File.read(settings_path), aliases: true)[Rails.env]
+ end
+
+ def settings_path
+ Rails.root.join('config', 'gitlab.yml')
+ end
+
+ def host
+ config['gitlab']['host']
+ end
+
+ def gl_subdomain?
+ GL_SUBDOMAIN_REGEX === host
+ end
+ end
+end