Sha256: 8f1367bb7f95a45eddc0e0b32b0528c87872b5d17a33fcde3be53cd661a64041

Contents?: true

Size: 903 Bytes

Versions: 5

Compression:

Stored size: 903 Bytes

Contents

require 'rack'
require 'flipper'
require 'flipper/api/middleware'

module Flipper
  module Api
    CONTENT_TYPE = 'application/json'.freeze

    def self.app(flipper)
      app = App.new(200,{ 'Content-Type' => CONTENT_TYPE }, [''])
      builder = Rack::Builder.new
      yield builder if block_given?
      builder.use Flipper::Api::Middleware, flipper
      builder.run app
      builder
    end

    class App
      # Public: HTTP response code
      # Use this method to update status code before responding
      attr_writer :status

      def initialize(status, headers, body)
        @status = status
        @headers = headers
        @body = body
      end

      # Public : Rack expects object that responds to call
      # env - environment hash
      def call(env)
        response
      end

      private

      def response
        [@status, @headers, @body]
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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