Sha256: 8d4b05f0785ec80e19eaf2300519b608b091c4a4de917c9b88a08d63fde64798

Contents?: true

Size: 840 Bytes

Versions: 7

Compression:

Stored size: 840 Bytes

Contents

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

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

    def self.app(flipper = nil, options = {})
      env_key = options.fetch(:env_key, 'flipper')
      app = ->(_) { [404, { 'Content-Type'.freeze => CONTENT_TYPE }, ['{}'.freeze]] }
      builder = Rack::Builder.new
      yield builder if block_given?
      builder.use Flipper::Api::JsonParams
      builder.use Flipper::Middleware::SetupEnv, flipper, env_key: env_key
      builder.use Flipper::Middleware::Memoizer, env_key: env_key
      builder.use Flipper::Api::Middleware, env_key: env_key
      builder.run app
      klass = self
      builder.define_singleton_method(:inspect) { klass.inspect } # pretty rake routes output
      builder
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
flipper-api-0.19.0 lib/flipper/api.rb
flipper-api-0.18.0 lib/flipper/api.rb
flipper-api-0.17.2 lib/flipper/api.rb
flipper-api-0.17.1 lib/flipper/api.rb
flipper-api-0.16.2 lib/flipper/api.rb
flipper-api-0.16.1 lib/flipper/api.rb
flipper-api-0.16.0 lib/flipper/api.rb