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
3mix-castronaut-0.5.0.2 vendor/rack/lib/rack/cascade.rb
kastner-rack-0.3.171 lib/rack/cascade.rb
kastner-rack-0.3.186 lib/rack/cascade.rb
masover-castronaut-0.4.4.4 vendor/rack/lib/rack/cascade.rb
masover-castronaut-0.4.4.5 vendor/rack/lib/rack/cascade.rb
masover-castronaut-0.5.0.1 vendor/rack/lib/rack/cascade.rb
p8-castronaut-0.6.1.1 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.2.0 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.2.5 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.3.0 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.3.5 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.3.6 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.4.1 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.4.2 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.4.3 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.4.4 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.4.5 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.4.6 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.5.0 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.5.1 vendor/rack/lib/rack/cascade.rb