summaryrefslogtreecommitdiff
path: root/lib/api/base.rb
blob: 33e47c18fcdcdf9f17a71dc39e0992d0240fcacc (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
# frozen_string_literal: true

module API
  class Base < Grape::API::Instance # rubocop:disable API/Base
    include ::Gitlab::WithFeatureCategory

    class << self
      def feature_category_for_app(app)
        feature_category_for_action(path_for_app(app))
      end

      def path_for_app(app)
        normalize_path(app.namespace, app.options[:path].first)
      end

      def route(methods, paths = ['/'], route_options = {}, &block)
        if category = route_options.delete(:feature_category)
          feature_category(category, Array(paths).map { |path| normalize_path(namespace, path) })
        end

        super
      end

      private

      def normalize_path(namespace, path)
        [namespace.presence, path.to_s.chomp('/').presence].compact.join('/')
      end
    end
  end
end