Sha256: 35e259de826339a6ba2de800ec6db19a2139c1457d0ec7b817cc37d2757991a7

Contents?: true

Size: 849 Bytes

Versions: 4

Compression:

Stored size: 849 Bytes

Contents

require 'flipper/api/v1/decorators/gate'

module Flipper
  module Api
    module V1
      module Decorators
        class Feature
          def initialize(feature)
            @feature = feature
          end

          # Public: Returns instance as hash that is ready to be json dumped.
          def as_json(exclude_gates: false, exclude_gate_names: false)
            result = {
              'key' => @feature.key,
              'state' => @feature.state.to_s,
            }

            unless exclude_gates
              gate_values = @feature.adapter.get(@feature)
              result['gates'] = @feature.gates.map do |gate|
                Decorators::Gate.new(gate, gate_values[gate.key]).as_json(exclude_name: exclude_gate_names)
              end
            end

            result
          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/feature.rb
flipper-api-1.3.1 lib/flipper/api/v1/decorators/feature.rb
flipper-api-1.3.0 lib/flipper/api/v1/decorators/feature.rb
flipper-api-1.3.0.pre lib/flipper/api/v1/decorators/feature.rb