Move #app from Connection to Builder

This commit is contained in:
technoweenie 2012-10-28 09:36:16 -06:00
parent 64892e2e9c
commit d10c01f111
2 changed files with 12 additions and 20 deletions

View File

@ -73,6 +73,17 @@ module Faraday
self.class.new(@handlers.dup)
end
def app
@app ||= begin
lock!
to_app(lambda { |env|
response = Response.new
response.finish(env) unless env.parallel?
env.response = response
})
end
end
def to_app(inner_app)
# last added handler is the deepest and thus closest to the inner app
@handlers.reverse.inject(inner_app) { |app, handler| handler.build(app) }

View File

@ -100,26 +100,7 @@ module Faraday
extend Forwardable
def_delegators :builder, :build, :use, :request, :response, :adapter
# The "rack app" wrapped in middleware. All requests are sent here.
#
# The builder is responsible for creating the app object. After this,
# the builder gets locked to ensure no further modifications are made
# to the middleware stack.
#
# Returns an object that responds to `call` and returns a Response.
def app
@app ||= begin
builder.lock!
builder.to_app(lambda { |env|
# the inner app that creates and returns the Response object
response = Response.new
response.finish(env) unless env.parallel?
env.response = response
})
end
end
def_delegators :builder, :build, :use, :request, :response, :adapter, :app
# Public: Makes an HTTP request without a body.
#