Commit fb5aa88c authored by Bob Van Landuyt's avatar Bob Van Landuyt

Make Gitlab::GlRepository#types an instance method

Having this as an instance method makes it easier to override in the
prepended `EE` module.

If we try to override this method on the module itself, it would not
be overridden correctly, depending on the load order.
parent 45f3aa99
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
module EE module EE
module Gitlab module Gitlab
module GlRepository module GlRepository
extend ::Gitlab::Utils::Override
extend ActiveSupport::Concern extend ActiveSupport::Concern
DESIGN = ::Gitlab::GlRepository::RepoType.new( DESIGN = ::Gitlab::GlRepository::RepoType.new(
...@@ -15,10 +16,9 @@ module EE ...@@ -15,10 +16,9 @@ module EE
DESIGN.name.to_s => DESIGN DESIGN.name.to_s => DESIGN
}.freeze }.freeze
class_methods do override :types
def types def types
super.merge(EE_TYPES) super.merge(EE_TYPES)
end
end end
end end
end end
......
...@@ -9,4 +9,12 @@ describe Gitlab::GlRepository do ...@@ -9,4 +9,12 @@ describe Gitlab::GlRepository do
expect(described_class.parse("design-#{project.id}")).to eq([project, EE::Gitlab::GlRepository::DESIGN]) expect(described_class.parse("design-#{project.id}")).to eq([project, EE::Gitlab::GlRepository::DESIGN])
end end
end end
describe '.types' do
it 'contains both the EE and CE repository types' do
expected_types = Gitlab::GlRepository::TYPES.merge(EE::Gitlab::GlRepository::EE_TYPES)
expect(described_class.types).to eq(expected_types)
end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
module Gitlab module Gitlab
module GlRepository class GlRepository
include Singleton
PROJECT = RepoType.new( PROJECT = RepoType.new(
name: :project, name: :project,
access_checker_class: Gitlab::GitAccess, access_checker_class: Gitlab::GitAccess,
...@@ -19,7 +21,7 @@ module Gitlab ...@@ -19,7 +21,7 @@ module Gitlab
}.freeze }.freeze
def self.types def self.types
TYPES instance.types
end end
def self.parse(gl_repository) def self.parse(gl_repository)
...@@ -39,7 +41,13 @@ module Gitlab ...@@ -39,7 +41,13 @@ module Gitlab
def self.default_type def self.default_type
PROJECT PROJECT
end end
def types
TYPES
end
private_class_method :instance
end end
end end
::Gitlab::GlRepository.prepend(::EE::Gitlab::GlRepository) Gitlab::GlRepository.prepend(::EE::Gitlab::GlRepository)
# frozen_string_literal: true # frozen_string_literal: true
module Gitlab module Gitlab
module GlRepository class GlRepository
class RepoType class RepoType
attr_reader :name, attr_reader :name,
:access_checker_class, :access_checker_class,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment