X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=ruby%2Flib%2Fruby%2Fgems%2F1.8%2Fgems%2Frack-1.1.2%2Flib%2Frack%2Fcascade.rb;fp=ruby%2Flib%2Fruby%2Fgems%2F1.8%2Fgems%2Frack-1.1.2%2Flib%2Frack%2Fcascade.rb;h=14c3e54d350f6f6da300a57d574eff3ccfa35ef8;hb=05ad905dae7df28a0baeee7739c8aab3de34c138;hp=0000000000000000000000000000000000000000;hpb=5fcbb31f4376cf38bd1745445a60d75a3758e71c;p=redminele%2Fredminele.git diff --git a/ruby/lib/ruby/gems/1.8/gems/rack-1.1.2/lib/rack/cascade.rb b/ruby/lib/ruby/gems/1.8/gems/rack-1.1.2/lib/rack/cascade.rb new file mode 100644 index 0000000..14c3e54 --- /dev/null +++ b/ruby/lib/ruby/gems/1.8/gems/rack-1.1.2/lib/rack/cascade.rb @@ -0,0 +1,41 @@ +module Rack + # Rack::Cascade tries an request on several apps, and returns the + # first response that is not 404 (or in a list of configurable + # status codes). + + class Cascade + NotFound = [404, {}, []] + + attr_reader :apps + + def initialize(apps, catch=404) + @apps = []; @has_app = {} + apps.each { |app| add app } + + @catch = {} + [*catch].each { |status| @catch[status] = true } + end + + def call(env) + result = NotFound + + @apps.each do |app| + result = app.call(env) + break unless @catch.include?(result[0].to_i) + end + + result + end + + def add app + @has_app[app] = true + @apps << app + end + + def include? app + @has_app.include? app + end + + alias_method :<<, :add + end +end