2021-09-28 08:11:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module EndpointAttributes
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
include Gitlab::ClassAttributes
|
|
|
|
|
2021-10-05 08:12:58 -04:00
|
|
|
DEFAULT_URGENCY = Config::REQUEST_URGENCIES.fetch(:default)
|
2021-09-28 08:11:10 -04:00
|
|
|
|
|
|
|
class_methods do
|
|
|
|
def feature_category(category, actions = [])
|
|
|
|
endpoint_attributes.set(actions, feature_category: category)
|
|
|
|
end
|
|
|
|
|
|
|
|
def feature_category_for_action(action)
|
|
|
|
category = endpoint_attributes.attribute_for_action(action, :feature_category)
|
|
|
|
category || superclass_feature_category_for_action(action)
|
|
|
|
end
|
|
|
|
|
2021-10-05 08:12:58 -04:00
|
|
|
def urgency(urgency_name, actions = [])
|
|
|
|
endpoint_attributes.set(actions, urgency: urgency_name)
|
2021-09-28 08:11:10 -04:00
|
|
|
end
|
|
|
|
|
2021-10-05 08:12:58 -04:00
|
|
|
def urgency_for_action(action)
|
|
|
|
urgency = endpoint_attributes.attribute_for_action(action, :urgency)
|
|
|
|
urgency || superclass_urgency_for_action(action) || DEFAULT_URGENCY
|
2021-09-28 08:11:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def endpoint_attributes
|
|
|
|
class_attributes[:endpoint_attributes_config] ||= Config.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def superclass_feature_category_for_action(action)
|
|
|
|
return unless superclass.respond_to?(:feature_category_for_action)
|
|
|
|
|
|
|
|
superclass.feature_category_for_action(action)
|
|
|
|
end
|
|
|
|
|
2021-10-05 08:12:58 -04:00
|
|
|
def superclass_urgency_for_action(action)
|
|
|
|
return unless superclass.respond_to?(:urgency_for_action)
|
2021-09-28 08:11:10 -04:00
|
|
|
|
2021-10-05 08:12:58 -04:00
|
|
|
superclass.urgency_for_action(action)
|
2021-09-28 08:11:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|