summaryrefslogtreecommitdiff
path: root/lib/api/entities/feature.rb
blob: 618a7be9c7b616c6995b8cca9c8f23cc2a14390b (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 API
  module Entities
    class Feature < Grape::Entity
      expose :name
      expose :state
      expose :gates, using: Entities::FeatureGate do |model|
        model.gates.map do |gate|
          value = model.gate_values[gate.key]

          # 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
    end
  end
end