Permalink
Browse files

stab one at automatically finding the rack root app and adding flash …

…to it
  • Loading branch information...
1 parent 3c1b93b commit caa922b5a571e3e9f70d71cda8d54457ed5945d2 @knzconnor knzconnor committed Apr 17, 2009
Showing with 23 additions and 1 deletion.
  1. +1 −1 example/base_app.ru
  2. +22 −0 lib/rack/flash.rb
View
@@ -17,6 +17,6 @@ class Base
end
end
use Rack::Session::Cookie
-use Rack::Flash, :flash_app_class => Base
+use Rack::Flash#, :flash_app_class => Base
use Rack::ShowExceptions
run Base.new
View
@@ -1,4 +1,21 @@
module Rack
+ class Builder
+ attr :ins
+ def use(middleware, *args, &block)
+ middleware.instance_variable_set "@rack_builder", self
+ @ins << lambda { |app|
+ middleware.new(app, *args, &block)
+ }
+ end
+
+ def run(app)
+ app.class.instance_variable_set "@rack_builder", self
+ @ins << app #lambda { |nothing| app }
+ end
+ end
+end
+
+module Rack
class Flash
# Raised when the session passed to FlashHash initialize is nil. This
# is usually an indicator that session middleware is not in use.
@@ -105,6 +122,11 @@ def initialize(app, opts={})
app_class.class_eval do
def flash; env['rack-flash'] end
end
+ else
+ rack_root_app = self.class.instance_variable_get("@rack_builder").ins.last
+ def rack_root_app.flash
+ env['rack-flash']
+ end
end
@app, @opts = app, opts
end

0 comments on commit caa922b

Please sign in to comment.