2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'active_support/inflector'
|
|
|
|
|
|
|
|
module InjectEnterpriseEditionModule
|
2021-06-08 01:23:25 +05:30
|
|
|
def prepend_mod_with(constant_name, namespace: Object, with_descendants: false)
|
|
|
|
each_extension_for(constant_name, namespace) do |constant|
|
|
|
|
prepend_module(constant, with_descendants)
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def extend_mod_with(constant_name, namespace: Object)
|
|
|
|
each_extension_for(
|
|
|
|
constant_name,
|
|
|
|
namespace,
|
|
|
|
&method(:extend))
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def include_mod_with(constant_name, namespace: Object)
|
|
|
|
each_extension_for(
|
|
|
|
constant_name,
|
|
|
|
namespace,
|
|
|
|
&method(:include))
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def prepend_mod(with_descendants: false)
|
|
|
|
prepend_mod_with(name, with_descendants: with_descendants) # rubocop: disable Cop/InjectEnterpriseEditionModule
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def extend_mod
|
|
|
|
extend_mod_with(name) # rubocop: disable Cop/InjectEnterpriseEditionModule
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def include_mod
|
|
|
|
include_mod_with(name) # rubocop: disable Cop/InjectEnterpriseEditionModule
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def prepend_module(mod, with_descendants)
|
|
|
|
prepend(mod)
|
|
|
|
|
|
|
|
if with_descendants
|
|
|
|
descendants.each { |descendant| descendant.prepend(mod) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def each_extension_for(constant_name, namespace)
|
|
|
|
Gitlab.extensions.each do |extension_name|
|
|
|
|
extension_namespace =
|
|
|
|
const_get_maybe_false(namespace, extension_name.upcase)
|
|
|
|
|
|
|
|
extension_module =
|
|
|
|
const_get_maybe_false(extension_namespace, constant_name)
|
|
|
|
|
|
|
|
yield(extension_module) if extension_module
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def const_get_maybe_false(mod, name)
|
2021-11-11 11:23:49 +05:30
|
|
|
mod && mod.const_defined?(name, false) && mod.const_get(name, false)
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
Module.prepend(InjectEnterpriseEditionModule)
|