Class: Flipper::UI::Middleware
- Inherits:
-
Object
- Object
- Flipper::UI::Middleware
- Defined in:
- lib/flipper/ui/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #call!(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/flipper/ui/middleware.rb', line 12 def initialize(app, = {}) @app = app @env_key = .fetch(:env_key, 'flipper') @flipper = .fetch(:flipper) { 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 @action_collection.add UI::Actions::Export @action_collection.add UI::Actions::Import @action_collection.add UI::Actions::Settings # Static Assets/Files @action_collection.add UI::Actions::File # Catch all redirect to features @action_collection.add UI::Actions::Home end |
Instance Method Details
#call(env) ⇒ Object
39 40 41 |
# File 'lib/flipper/ui/middleware.rb', line 39 def call(env) dup.call!(env) end |
#call!(env) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/flipper/ui/middleware.rb', line 43 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) { Flipper } action_class.run(flipper, request) end end |