Sha256: 52926486336dc85796d32276b270550d753ecf80b195ae8534c4e8f209d79daa

Contents?: true

Size: 927 Bytes

Versions: 12

Compression:

Stored size: 927 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')
      memoizer_options = options.fetch(:memoizer_options, {})

      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, memoizer_options.merge(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

12 entries across 12 versions & 1 rubygems

Version Path
flipper-api-0.21.0 lib/flipper/api.rb
flipper-api-0.21.0.rc2 lib/flipper/api.rb
flipper-api-0.21.0.rc1 lib/flipper/api.rb
flipper-api-0.20.4 lib/flipper/api.rb
flipper-api-0.20.3 lib/flipper/api.rb
flipper-api-0.20.2 lib/flipper/api.rb
flipper-api-0.20.1 lib/flipper/api.rb
flipper-api-0.20.0 lib/flipper/api.rb
flipper-api-0.20.0.beta3 lib/flipper/api.rb
flipper-api-0.20.0.beta2 lib/flipper/api.rb
flipper-api-0.20.0.beta1 lib/flipper/api.rb
flipper-api-0.19.1 lib/flipper/api.rb