debian-mirror-gitlab/lib/gitlab/etag_caching/router.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
1.1 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module EtagCaching
2021-04-17 20:07:23 +05:30
module Router
2022-05-07 20:08:51 +05:30
Route = Struct.new(:router, :regexp, :name, :feature_category, :caller_id) do
2021-04-17 20:07:23 +05:30
delegate :match, to: :regexp
delegate :cache_key, to: :router
end
2017-09-10 17:25:29 +05:30
2021-04-17 20:07:23 +05:30
module Helpers
def build_route(attrs)
2022-05-07 20:08:51 +05:30
EtagCaching::Router::Route.new(self, *attrs)
end
def build_rails_route(attrs)
regexp, name, controller, action_name = *attrs
EtagCaching::Router::Route.new(
self,
regexp,
name,
controller.feature_category_for_action(action_name).to_s,
controller.endpoint_id_for_action(action_name).to_s
)
2021-04-17 20:07:23 +05:30
end
end
2017-08-17 22:00:37 +05:30
2022-05-07 20:08:51 +05:30
# Performing Rails routing match before GraphQL would be more expensive
2021-04-17 20:07:23 +05:30
# for the GraphQL requests because we need to traverse all of the RESTful
# route definitions before falling back to GraphQL.
def self.match(request)
2022-05-07 20:08:51 +05:30
Router::Graphql.match(request) || Router::Rails.match(request)
2017-08-17 22:00:37 +05:30
end
end
end
end