Sha256: 3058beea4d365f3972924a2b135756900d8bc6f4935870150a43493f5b175f76
Contents?: true
Size: 1.18 KB
Versions: 3
Compression:
Stored size: 1.18 KB
Contents
module Flipper module Middleware class SetupEnv # Public: Initializes an instance of the SetEnv middleware. Allows for # lazy initialization of the flipper instance being set in the env by # providing a block. # # app - The app this middleware is included in. # flipper_or_block - The Flipper::DSL instance or a block that yields a # Flipper::DSL instance to use for all operations. # # Examples # # flipper = Flipper.new(...) # # # using with a normal flipper instance # use Flipper::Middleware::SetEnv, flipper # # # using with a block that yields a flipper instance # use Flipper::Middleware::SetEnv, lambda { Flipper.new(...) } # def initialize(app, flipper_or_block) @app = app if flipper_or_block.respond_to?(:call) @flipper_block = flipper_or_block else @flipper = flipper_or_block end end def call(env) env['flipper'.freeze] ||= flipper @app.call(env) end private def flipper @flipper ||= @flipper_block.call end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
flipper-0.11.0.beta4 | lib/flipper/middleware/setup_env.rb |
flipper-0.11.0.beta3 | lib/flipper/middleware/setup_env.rb |
flipper-0.11.0.beta1 | lib/flipper/middleware/setup_env.rb |