lib/rack/pact_broker/cascade.rb
# Call each app in order.  If the responses uses a status that requires
# cascading, try the next app.  If all responses require cascading,
# return the response from the last app.
Call each app in order.  If the responses uses a status that requires
cascading, try the next app.  If all responses require cascading,
return the response from the last app.
Call each app in order . If the responses uses a status that requires cascading try the next app . If all responses require cascading return the response from the last app .
def call(env)
        return [404, { CONTENT_TYPE => "text/plain" }, []] if @apps.empty?
        result = nil
        last_body = nil
        @apps.each_with_index do |app, i|
          last_body.close if last_body.respond_to? :close
          result = app.call(env)
          puts result.last
          if @cascade_for.include?(result[0].to_i) && result[2].respond_to?(:empty?) && result[2].empty?
            last_body = result[2]
          else
            puts "returned from #{i} of #{@apps.size}"
            return result
          end
        end
        result
      end
def call ( env ) return [ 404 , { CONTENT_TYPE => "text/plain" } , [ ] ] if @apps . empty? result = nil last_body = nil @apps . each_with_index do | app , i | last_body . close if last_body . respond_to? :close result = app . call ( env ) puts result . last if @cascade_for . include? ( result [ 0 ] . to_i ) && result [ 2 ] . respond_to? ( :empty? ) && result [ 2 ] . empty? last_body = result [ 2 ] else puts "returned from #{i} of #{@apps.size}" return result end end result end
Call each app in order.
Call each app in order .
# The SPEC says that the body must be closed after it has been iterated # by the server, or if it is replaced by a middleware action. Cascade # replaces the body each time a cascade happens. It is assumed that nil # does not respond to close, otherwise the previous application body # will be closed. The final application body will not be closed, as it # will be passed to the server as a result. # If it is a 404/403 AND the response body is empty, then try the next app # otherwise, return the result
env