Sha256: 5d663c6b4e48eff5a7f1f7684f03e25ab1e7390fd04c47ec6ec369246821e741

Contents?: true

Size: 931 Bytes

Versions: 3

Compression:

Stored size: 931 Bytes

Contents

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

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

3 entries across 3 versions & 1 rubygems

Version Path
flipper-api-0.10.2 lib/flipper/api.rb
flipper-api-0.10.1 lib/flipper/api.rb
flipper-api-0.10.0 lib/flipper/api.rb