Sha256: 9e1ec9f6af73d5461f75a014b7b6a1a78608cf21c2fbf2fe598888498eb1cc18

Contents?: true

Size: 998 Bytes

Versions: 5

Compression:

Stored size: 998 Bytes

Contents

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

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

          route %r{api/v1/features/[^/]*/?\Z}

          def get
            if feature_names.include?(feature_name)
              feature = Decorators::Feature.new(flipper[feature_name])
              json_response(feature.as_json)
            else
              json_response({}, 404)
            end
          end

          def delete
            if feature_names.include?(feature_name)
              flipper.remove(feature_name)

              json_response({}, 204)
            else
              json_response({}, 404)
            end
          end

          private

          def feature_name
            @feature_name ||= Rack::Utils.unescape(path_parts.last)
          end

          def feature_names
            @feature_names ||= flipper.adapter.features
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flipper-api-0.9.2 lib/flipper/api/v1/actions/feature.rb
flipper-api-0.9.1 lib/flipper/api/v1/actions/feature.rb
flipper-api-0.9.0 lib/flipper/api/v1/actions/feature.rb
flipper-api-0.9.0.beta1 lib/flipper/api/v1/actions/feature.rb
flipper-api-0.8.0 lib/flipper/api/v1/actions/feature.rb