Permalink
Browse files

AD::Cascade that supports X-Cascade

  • Loading branch information...
1 parent 673fa7f commit feb7382047bf5e354edd12aa89895ec4591a5614 @josh josh committed Dec 26, 2009
Showing with 30 additions and 0 deletions.
  1. +1 −0 actionpack/lib/action_dispatch.rb
  2. +29 −0 actionpack/lib/action_dispatch/middleware/cascade.rb
@@ -41,6 +41,7 @@ module ActionDispatch
autoload_under 'middleware' do
autoload :Callbacks
+ autoload :Cascade
autoload :ParamsParser
autoload :Rescue
autoload :ShowExceptions
@@ -0,0 +1,29 @@
+module ActionDispatch
+ class Cascade
+ def self.new(*apps)
+ apps = apps.flatten
+
+ case apps.length
+ when 0
+ raise ArgumentError, "app is required"
+ when 1
+ apps.first
+ else
+ super(apps)
+ end
+ end
+
+ def initialize(apps)
+ @apps = apps
+ end
+
+ def call(env)
+ result = nil
+ @apps.each do |app|
+ result = app.call(env)
+ break unless result[1]["X-Cascade"] == "pass"
+ end
+ result
+ end
+ end
+end

0 comments on commit feb7382

Please sign in to comment.