Sha256: 490c6b4b7846bfb05b37e40f840b2b9a64ab33f5befa8563a618cbf2b9c1da98

Contents?: true

Size: 1.48 KB

Versions: 10

Compression:

Stored size: 1.48 KB

Contents

require 'flipper/api/action'
require 'flipper/api/v1/decorators/feature'

module Flipper
  module Api
    module V1
      module Actions
        class Features < Api::Action
          route(/features\Z/)

          def get
            keys = params['keys']
            features = if keys
                         names = keys.split(',')
                         if names.empty?
                           []
                         else
                           existing_feature_names = names.keep_if do |feature_name|
                             feature_exists?(feature_name)
                           end

                           flipper.preload(existing_feature_names)
                         end
                       else
                         flipper.features
                       end

            decorated_features = features.map do |feature|
              Decorators::Feature.new(feature).as_json
            end

            json_response(features: decorated_features)
          end

          def post
            feature_name = params.fetch('name') { json_error_response(:name_invalid) }
            feature = flipper[feature_name]
            flipper.adapter.add(feature)
            decorated_feature = Decorators::Feature.new(feature)
            json_response(decorated_feature.as_json, 200)
          end

          private

          def feature_exists?(feature_name)
            flipper.features.map(&:key).include?(feature_name)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
flipper-api-0.11.0 lib/flipper/api/v1/actions/features.rb
flipper-api-0.11.0.rc1 lib/flipper/api/v1/actions/features.rb
flipper-api-0.11.0.beta9 lib/flipper/api/v1/actions/features.rb
flipper-api-0.11.0.beta8 lib/flipper/api/v1/actions/features.rb
flipper-api-0.11.0.beta7 lib/flipper/api/v1/actions/features.rb
flipper-api-0.11.0.beta6 lib/flipper/api/v1/actions/features.rb
flipper-api-0.11.0.beta5 lib/flipper/api/v1/actions/features.rb
flipper-api-0.11.0.beta4 lib/flipper/api/v1/actions/features.rb
flipper-api-0.11.0.beta3 lib/flipper/api/v1/actions/features.rb
flipper-api-0.11.0.beta1 lib/flipper/api/v1/actions/features.rb