File: feature.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (34 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module API
  module Entities
    class Feature < Grape::Entity
      expose :name, documentation: { type: 'string', example: 'experimental_feature' }
      expose :state, documentation: { type: 'string', example: 'off' }
      expose :gates, using: Entities::FeatureGate do |model|
        model.gates.map do |gate|
          # in Flipper 0.26.1, they removed two GateValues#[] method calls for performance reasons
          # https://github.com/flippercloud/flipper/pull/706/commits/ed914b6adc329455a634be843c38db479299efc7
          # https://github.com/flippercloud/flipper/commit/eee20f3ae278d168c8bf70a7a5fcc03bedf432b5
          value = model.gate_values.send(gate.key) # rubocop:disable GitlabSecurity/PublicSend
          # By default all gate values are populated. Only show relevant ones.
          if (value.is_a?(Integer) && value == 0) || (value.is_a?(Set) && value.empty?)
            next
          end

          { key: gate.key, value: value }
        end.compact
      end

      class Definition < Grape::Entity
        ::Feature::Definition::PARAMS.each do |param|
          expose param
        end
      end

      expose :definition, using: Definition do |feature|
        ::Feature::Definition.definitions[feature.name.to_sym]
      end
    end
  end
end