File: gate.rb

package info (click to toggle)
ruby-flipper 0.13.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,824 kB
  • sloc: ruby: 13,183; sh: 54; makefile: 14
file content (37 lines) | stat: -rw-r--r-- 828 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
36
37
require 'delegate'

module Flipper
  module UI
    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

        # Public: Returns instance as hash that is ready to be json dumped.
        def as_json
          value_as_json =
            case data_type
            when :set
              value.to_a # json doesn't like sets
            else
              value
            end

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