class Flipper::Api::Middleware
Public Class Methods
new(app, options = {})
click to toggle source
# File lib/flipper/api/middleware.rb, line 12 def initialize(app, options = {}) @app = app @env_key = options.fetch(:env_key, 'flipper') @action_collection = ActionCollection.new @action_collection.add Api::V1::Actions::PercentageOfTimeGate @action_collection.add Api::V1::Actions::PercentageOfActorsGate @action_collection.add Api::V1::Actions::ActorsGate @action_collection.add Api::V1::Actions::GroupsGate @action_collection.add Api::V1::Actions::BooleanGate @action_collection.add Api::V1::Actions::ClearFeature @action_collection.add Api::V1::Actions::Actors @action_collection.add Api::V1::Actions::Feature @action_collection.add Api::V1::Actions::Features end
Public Instance Methods
call(env)
click to toggle source
# File lib/flipper/api/middleware.rb, line 28 def call(env) dup.call!(env) end
call!(env)
click to toggle source
# File lib/flipper/api/middleware.rb, line 32 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