File: gate.rb

package info (click to toggle)
ruby-flipper 0.17.1-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,896 kB
  • sloc: ruby: 13,876; sh: 55; makefile: 14
file content (35 lines) | stat: -rw-r--r-- 760 bytes parent folder | download | duplicates (4)
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
35
module Flipper
  module Api
    module V1
      module Decorators
        class Gate < SimpleDelegator
          # Public the gate being decorated
          alias_method :gate, :__getobj__

          # Public: the value for the gate from the adapter.
          attr_reader :value

          def initialize(gate, value = nil)
            super gate
            @value = value
          end

          def as_json
            {
              'key' => gate.key.to_s,
              'name' => gate.name.to_s,
              'value' => value_as_json,
            }
          end

          private

          # json doesn't like sets
          def value_as_json
            data_type == :set ? value.to_a : value
          end
        end
      end
    end
  end
end