Sha256: 58812c425203d800174b21e3ee90616fe65979bb8b79d9acbf8719ba34396aca

Contents?: true

Size: 869 Bytes

Versions: 14

Compression:

Stored size: 869 Bytes

Contents

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

module Flipper
  module Api
    module V1
      module Decorators
        class Feature < SimpleDelegator
          # Public: The feature being decorated.
          alias_method :feature, :__getobj__

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

            unless exclude_gates
              gate_values = feature.adapter.get(self)
              result['gates'] = 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

14 entries across 14 versions & 1 rubygems

Version Path
flipper-api-1.2.2 lib/flipper/api/v1/decorators/feature.rb
flipper-api-1.2.1 lib/flipper/api/v1/decorators/feature.rb
flipper-api-1.2.0 lib/flipper/api/v1/decorators/feature.rb
flipper-api-1.1.2 lib/flipper/api/v1/decorators/feature.rb
flipper-api-1.1.1 lib/flipper/api/v1/decorators/feature.rb
flipper-api-1.1.0 lib/flipper/api/v1/decorators/feature.rb
flipper-api-1.0.0 lib/flipper/api/v1/decorators/feature.rb
flipper-api-1.0.0.pre lib/flipper/api/v1/decorators/feature.rb
flipper-api-0.28.3 lib/flipper/api/v1/decorators/feature.rb
flipper-api-0.28.2 lib/flipper/api/v1/decorators/feature.rb
flipper-api-0.28.1 lib/flipper/api/v1/decorators/feature.rb
flipper-api-0.28.0 lib/flipper/api/v1/decorators/feature.rb
flipper-api-0.27.1 lib/flipper/api/v1/decorators/feature.rb
flipper-api-0.27.0 lib/flipper/api/v1/decorators/feature.rb