Class: Rack::Cascade
Overview
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).
Instance Attribute Summary collapse
-
#apps ⇒ Object
readonly
Returns the value of attribute apps.
Instance Method Summary collapse
- #add(app) ⇒ Object (also: #<<)
- #call(env) ⇒ Object
- #include?(app) ⇒ Boolean
-
#initialize(apps, catch = 404) ⇒ Cascade
constructor
A new instance of Cascade.
Constructor Details
#initialize(apps, catch = 404) ⇒ Cascade
Returns a new instance of Cascade.
9 10 11 12 |
# File 'lib/gems/rack-0.9.1/lib/rack/cascade.rb', line 9 def initialize(apps, catch=404) @apps = apps @catch = [*catch] end |
Instance Attribute Details
#apps ⇒ Object (readonly)
Returns the value of attribute apps.
7 8 9 |
# File 'lib/gems/rack-0.9.1/lib/rack/cascade.rb', line 7 def apps @apps end |
Instance Method Details
#add(app) ⇒ Object Also known as: <<
26 27 28 |
# File 'lib/gems/rack-0.9.1/lib/rack/cascade.rb', line 26 def add app @apps << app end |
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gems/rack-0.9.1/lib/rack/cascade.rb', line 14 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 |
#include?(app) ⇒ Boolean
30 31 32 |
# File 'lib/gems/rack-0.9.1/lib/rack/cascade.rb', line 30 def include? app @apps.include? app end |