Sha256: 6e1e27d608bfdea09d98ccc05707bbfe24599ef16cf6a20291264c0e2894aacd

Contents?: true

Size: 836 Bytes

Versions: 8

Compression:

Stored size: 836 Bytes

Contents

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(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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
flipper-api-1.0.0 lib/flipper/api/v1/decorators/gate.rb
flipper-api-1.0.0.pre lib/flipper/api/v1/decorators/gate.rb
flipper-api-0.28.3 lib/flipper/api/v1/decorators/gate.rb
flipper-api-0.28.2 lib/flipper/api/v1/decorators/gate.rb
flipper-api-0.28.1 lib/flipper/api/v1/decorators/gate.rb
flipper-api-0.28.0 lib/flipper/api/v1/decorators/gate.rb
flipper-api-0.27.1 lib/flipper/api/v1/decorators/gate.rb
flipper-api-0.27.0 lib/flipper/api/v1/decorators/gate.rb