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
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rack-0.4.0/lib/rack/cascade.rb
middleman-0.10.17 vendor/gems/gems/rack-1.0.1/lib/rack/cascade.rb
middleman-0.10.16 vendor/gems/gems/rack-1.0.1/lib/rack/cascade.rb
middleman-0.10.15 vendor/gems/gems/rack-1.0.1/lib/rack/cascade.rb
rackjour-0.1.8 vendor/gems/gems/rack-1.0.1/lib/rack/cascade.rb
middleman-0.10.14 vendor/gems/gems/rack-1.0.1/lib/rack/cascade.rb
rack-1.0.1 lib/rack/cascade.rb
webroar-0.2.2 src/admin_panel/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/cascade.rb
actionpack-2.3.2 lib/action_controller/vendor/rack-1.0/rack/cascade.rb
mack-0.8.2 lib/gems/rack-0.4.0/lib/rack/cascade.rb
mack-0.8.3.1 lib/gems/rack-0.9.1/lib/rack/cascade.rb
mack-0.8.3 lib/gems/rack-0.9.1/lib/rack/cascade.rb
passenger-2.1.2 vendor/rack-0.9.1/lib/rack/cascade.rb
passenger-2.2.1 vendor/rack-0.9.1/lib/rack/cascade.rb
passenger-2.2.0 vendor/rack-0.9.1/lib/rack/cascade.rb
passenger-2.1.3 vendor/rack-0.9.1/lib/rack/cascade.rb
passenger-2.2.2 vendor/rack-1.0.0-git/lib/rack/cascade.rb
rack-0.9.0 lib/rack/cascade.rb
rack-0.4.0 lib/rack/cascade.rb
rack-0.9.1 lib/rack/cascade.rb