summaryrefslogtreecommitdiff
path: root/lib/gitlab/routing.rb
blob: ac1e864433b5831b02167fc026bc77b2760106aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Gitlab
  module Routing
    extend ActiveSupport::Concern

    mattr_accessor :_includers
    self._includers = []

    included do
      Gitlab::Routing._includers << self
      include Gitlab::Routing.url_helpers
    end

    def self.add_helpers(mod)
      url_helpers.include mod
      url_helpers.extend mod

      app_url_helpers = Gitlab::Application.routes.named_routes.url_helpers_module
      app_url_helpers.include mod
      app_url_helpers.extend mod

      GitlabRoutingHelper.include mod
      GitlabRoutingHelper.extend mod

      _includers.each do |klass|
        klass.include mod
      end
    end

    # Returns the URL helpers Module.
    #
    # This method caches the output as Rails' "url_helpers" method creates an
    # anonymous module every time it's called.
    #
    # Returns a Module.
    def self.url_helpers
      @url_helpers ||= Gitlab::Application.routes.url_helpers
    end
  end
end