summaryrefslogtreecommitdiff
path: root/app/graphql/types/base_enum.rb
blob: 159443641bc3df1b05883eafac27dff5b969ac3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

module Types
  class BaseEnum < GraphQL::Schema::Enum
    extend GitlabStyleDeprecations

    class << self
      def value(*args, **kwargs, &block)
        enum[args[0].downcase] = kwargs[:value] || args[0]
        kwargs = gitlab_deprecation(kwargs)

        super(*args, **kwargs, &block)
      end

      # Returns an indifferent access hash with the key being the downcased name of the attribute
      # and the value being the Ruby value (either the explicit `value` passed or the same as the value attr).
      def enum
        @enum_values ||= {}.with_indifferent_access
      end
    end
  end
end