Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-09-28 15:11:10 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-28 15:11:10 +0300
commit24e5ef9b1a56019d7ea6deb41e8c8cbe5f0a59a3 (patch)
tree9590894b19bd66573068c5dce417939f14aa7590 /lib/gitlab/endpoint_attributes.rb
parentf4963c8c9bb2b6c38e9bd3016494a27c6c91e7e6 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/endpoint_attributes.rb')
-rw-r--r--lib/gitlab/endpoint_attributes.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/gitlab/endpoint_attributes.rb b/lib/gitlab/endpoint_attributes.rb
new file mode 100644
index 00000000000..11e41863cb8
--- /dev/null
+++ b/lib/gitlab/endpoint_attributes.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module EndpointAttributes
+ extend ActiveSupport::Concern
+ include Gitlab::ClassAttributes
+
+ DEFAULT_TARGET_DURATION = Config::TARGET_DURATIONS.fetch(:medium)
+
+ 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
+
+ def target_duration(duration, actions = [])
+ endpoint_attributes.set(actions, target_duration: duration)
+ end
+
+ def target_duration_for_action(action)
+ duration = endpoint_attributes.attribute_for_action(action, :target_duration)
+ duration || superclass_target_duration_for_action(action) || DEFAULT_TARGET_DURATION
+ 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
+
+ def superclass_target_duration_for_action(action)
+ return unless superclass.respond_to?(:target_duration_for_action)
+
+ superclass.target_duration_for_action(action)
+ end
+ end
+ end
+end