Sha256: f2c65498f19713cd506f4c706f70b5a9e7ea962b99c91917816ff16b1efdd454

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

require 'pathname'
require 'rack'
begin
  # Rack 2
  require 'rack/method_override'
rescue LoadError
  require 'rack/methodoverride'
end
require 'rack/protection'

require 'flipper'
require 'flipper/ui/middleware'
require 'flipper/ui/configuration'

module Flipper
  module UI
    def self.root
      @root ||= Pathname(__FILE__).dirname.expand_path.join('ui')
    end

    def self.app(flipper = nil, options = {})
      env_key = options.fetch(:env_key, 'flipper')
      rack_protection_options = options.fetch(:rack_protection, use: :authenticity_token)

      app = ->(_) { [200, { 'content-type' => 'text/html' }, ['']] }
      builder = Rack::Builder.new
      yield builder if block_given?
      builder.use Rack::Protection, rack_protection_options
      builder.use Rack::MethodOverride
      builder.use Flipper::Middleware::SetupEnv, flipper, env_key: env_key
      builder.use Flipper::UI::Middleware, flipper: flipper, env_key: env_key
      builder.run app
      klass = self
      app = builder.to_app
      app.define_singleton_method(:inspect) { klass.inspect } # pretty rake routes output
      app
    end

    # Public: yields configuration instance for customizing UI text
    def self.configure
      yield(configuration)
    end

    def self.configuration
      @configuration ||= ::Flipper::UI::Configuration.new
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flipper-ui-1.1.2 lib/flipper/ui.rb
flipper-ui-1.1.1 lib/flipper/ui.rb
flipper-ui-1.1.0 lib/flipper/ui.rb
flipper-ui-1.0.0 lib/flipper/ui.rb
flipper-ui-1.0.0.pre lib/flipper/ui.rb