Sha256: 5ce443c6c1e7d3e8cac8ad5aea82b8fb4e1b58fd00decc0612d21e764a5a8461

Contents?: true

Size: 852 Bytes

Versions: 1

Compression:

Stored size: 852 Bytes

Contents

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

module Flipper
  module Api
    module V1
      module Actions
        class Features < Api::Action

          route %r{api/v1/features\Z}

          def get
            features = flipper.features.map { |feature|
              Decorators::Feature.new(feature).as_json
            }

            json_response({
              features: features
            })
          end

          def post
            feature_name = params.fetch('name') do
              json_response({
                errors: [{
                  message: 'Missing post parameter: name',
                }]
              }, 422)
            end

            flipper.adapter.add(flipper[feature_name])
            json_response({}, 200)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flipper-api-0.9.2 lib/flipper/api/v1/actions/features.rb