Sha256: 16a540070c4f07d3505168c6523a15f65fb6d6f23fa4d36a8aef106fbdfcf07f

Contents?: true

Size: 788 Bytes

Versions: 4

Compression:

Stored size: 788 Bytes

Contents

module Flipper
  module Api
    module V1
      module Decorators
        class Gate
          def initialize(gate, value = nil)
            @gate = gate
            @value = value
          end

          def as_json(exclude_name: false)
            as_json = {
              'key' => @gate.key.to_s,
              'value' => value_as_json,
            }
            as_json['name'] = @gate.name.to_s unless exclude_name
            as_json
          end

          private

          # Set of types that should be represented as Array in JSON.
          JSON_ARRAY_TYPES = Set[:set].freeze

          # json doesn't like sets
          def value_as_json
            JSON_ARRAY_TYPES.include?(@gate.data_type) ? @value.to_a : @value
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
flipper-api-1.3.2 lib/flipper/api/v1/decorators/gate.rb
flipper-api-1.3.1 lib/flipper/api/v1/decorators/gate.rb
flipper-api-1.3.0 lib/flipper/api/v1/decorators/gate.rb
flipper-api-1.3.0.pre lib/flipper/api/v1/decorators/gate.rb