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:
Diffstat (limited to 'lib/declarative_enum.rb')
-rw-r--r--lib/declarative_enum.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/declarative_enum.rb b/lib/declarative_enum.rb
index 8dea9d6130b..7875e0ba4f3 100644
--- a/lib/declarative_enum.rb
+++ b/lib/declarative_enum.rb
@@ -15,9 +15,9 @@
# TEXT
#
# define do
-# acceptable_risk value: 0, description: 'The vulnerability is known but is considered to be an acceptable business risk.'
-# false_positive value: 1, description: 'An error in reporting the presence of a vulnerability in a system when the vulnerability is not present.'
-# used_in_tests value: 2, description: 'The finding is not a vulnerability because it is part of a test or is test data.'
+# acceptable_risk value: 0, description: N_('The vulnerability is known but is considered to be an acceptable business risk.')
+# false_positive value: 1, description: N_('An error in reporting the presence of a vulnerability in a system when the vulnerability is not present.')
+# used_in_tests value: 2, description: N_('The finding is not a vulnerability because it is part of a test or is test data.')
# end
#
# Then we can use this module to register enums for our Active Record models like so,
@@ -63,6 +63,19 @@ module DeclarativeEnum
@description
end
+ def values
+ definition.transform_values { |definition| definition[:value] }
+ end
+
+ # Return list of dynamically translated descriptions.
+ #
+ # It is required to define descriptions with `N_(...)`.
+ #
+ # See https://github.com/grosser/fast_gettext#n_-and-nn_-make-dynamic-translations-available-to-the-parser
+ def translated_descriptions
+ definition.transform_values { |definition| _(definition[:description]) }
+ end
+
def define(&block)
raise LocalJumpError, 'No block given' unless block