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
relevance-castronaut-0.5.2 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.5.3 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.5.4 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.6.0 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.6.1 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.7.4 vendor/rack/lib/rack/cascade.rb
relevance-castronaut-0.7.5 vendor/rack/lib/rack/cascade.rb
technomancy-rack-0.3.0 lib/rack/cascade.rb
timocratic-rack-1.0.0 lib/rack/cascade.rb
nbudin-castronaut-0.7.5 vendor/rack/lib/rack/cascade.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/lib/rack/cascade.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/lib/rack/cascade.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/lib/rack/cascade.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/lib/rack/cascade.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/lib/rack/cascade.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/rack-1.0.1/lib/rack/cascade.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/rack-1.0.1/lib/rack/cascade.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/rack-1.0.1/lib/rack/cascade.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/rack-1.0.1/lib/rack/cascade.rb
middleman-0.12.0.pre lib/middleman/vendor/gems/gems/rack-1.0.1/lib/rack/cascade.rb