Sha256: b861def5999d96e303dcaca4d4a81e562aff825eaf3dc0a66e5ef8ae69035c79

Contents?: true

Size: 1.42 KB

Versions: 19

Compression:

Stored size: 1.42 KB

Contents

require 'rack'
require 'flipper/ui/action_collection'

# Require all actions automatically.
Pathname(__FILE__).dirname.join('actions').each_child(false) do |name|
  require "flipper/ui/actions/#{name}"
end

module Flipper
  module UI
    class Middleware
      def initialize(app, options = {})
        @app = app
        @env_key = options.fetch(:env_key, 'flipper')

        @action_collection = ActionCollection.new

        # UI
        @action_collection.add UI::Actions::AddFeature
        @action_collection.add UI::Actions::ActorsGate
        @action_collection.add UI::Actions::GroupsGate
        @action_collection.add UI::Actions::BooleanGate
        @action_collection.add UI::Actions::PercentageOfTimeGate
        @action_collection.add UI::Actions::PercentageOfActorsGate
        @action_collection.add UI::Actions::Feature
        @action_collection.add UI::Actions::Features

        # Static Assets/Files
        @action_collection.add UI::Actions::File

        # Catch all redirect to features
        @action_collection.add UI::Actions::Home
      end

      def call(env)
        dup.call!(env)
      end

      def call!(env)
        request = Rack::Request.new(env)
        action_class = @action_collection.action_for_request(request)

        if action_class.nil?
          @app.call(env)
        else
          flipper = env.fetch(@env_key)
          action_class.run(flipper, request)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
flipper-ui-0.21.0 lib/flipper/ui/middleware.rb
flipper-ui-0.21.0.rc2 lib/flipper/ui/middleware.rb
flipper-ui-0.21.0.rc1 lib/flipper/ui/middleware.rb
flipper-ui-0.20.4 lib/flipper/ui/middleware.rb
flipper-ui-0.20.3 lib/flipper/ui/middleware.rb
flipper-ui-0.20.2 lib/flipper/ui/middleware.rb
flipper-ui-0.20.1 lib/flipper/ui/middleware.rb
flipper-ui-0.20.0 lib/flipper/ui/middleware.rb
flipper-ui-0.20.0.beta3 lib/flipper/ui/middleware.rb
flipper-ui-0.20.0.beta2 lib/flipper/ui/middleware.rb
flipper-ui-0.20.0.beta1 lib/flipper/ui/middleware.rb
flipper-ui-0.19.1 lib/flipper/ui/middleware.rb
flipper-ui-0.19.0 lib/flipper/ui/middleware.rb
flipper-ui-0.18.0 lib/flipper/ui/middleware.rb
flipper-ui-0.17.2 lib/flipper/ui/middleware.rb
flipper-ui-0.17.1 lib/flipper/ui/middleware.rb
flipper-ui-0.16.2 lib/flipper/ui/middleware.rb
flipper-ui-0.16.1 lib/flipper/ui/middleware.rb
flipper-ui-0.16.0 lib/flipper/ui/middleware.rb