Sha256: 05db24b156da9c0e59705f35e2a123a59f7fd9e5335aa1a02b3df19361c1ffed
Contents?: true
Size: 741 Bytes
Versions: 63
Compression:
Stored size: 741 Bytes
Contents
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 attr_reader :apps def initialize(apps, catch=404) @apps = apps @catch = [*catch] end def call(env) status = headers = body = nil raise ArgumentError, "empty cascade" if @apps.empty? @apps.each { |app| begin status, headers, body = app.call(env) break unless @catch.include?(status.to_i) end } [status, headers, body] end def add app @apps << app end def include? app @apps.include? app end alias_method :<<, :add end end
Version data entries
63 entries across 63 versions & 18 rubygems
Version | Path |
---|---|
rack-1.0.0 | lib/rack/cascade.rb |
radiant-0.8.0 | vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/cascade.rb |
sinatra-0.2.2 | vendor/rack/lib/rack/cascade.rb |