diff options
author | Oscar Del Ben <info@oscardelben.com> | 2012-06-13 08:59:14 -0700 |
---|---|---|
committer | Oscar Del Ben <info@oscardelben.com> | 2012-06-13 08:59:14 -0700 |
commit | 18faa5b3375daa2b090a360e4a24649f9a4e03d2 (patch) | |
tree | 4375609a4ff6aee2644461b36c360db1019be0e6 /guides/source/initialization.textile | |
parent | 1f07ff97ab416ba54b4cecde2be1a22341dfa09e (diff) | |
download | rails-18faa5b3375daa2b090a360e4a24649f9a4e03d2.tar.gz rails-18faa5b3375daa2b090a360e4a24649f9a4e03d2.tar.bz2 rails-18faa5b3375daa2b090a360e4a24649f9a4e03d2.zip |
Show when Rack middlewares are executed
Diffstat (limited to 'guides/source/initialization.textile')
-rw-r--r-- | guides/source/initialization.textile | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile index bf901508c8..1f94dc1419 100644 --- a/guides/source/initialization.textile +++ b/guides/source/initialization.textile @@ -572,3 +572,43 @@ all the engines available by providing the +initializers+ method. After this is done we go back to +Rack::Server+ +h4. Rack: lib/rack/server.rb + +Last time we left when the +app+ method was being defined: + +<ruby> +def app + @app ||= begin + if !::File.exist? options[:config] + abort "configuration #{options[:config]} not found" + end + + app, options = Rack::Builder.parse_file(self.options[:config], opt_parser) + self.options.merge! options + app + end +end +</ruby> + +At this point +app+ is the Rails app itself (a middleware), and what +happens next is Rack will call all the provided middlewares: + +<ruby> +def build_app(app) + middleware[options[:environment]].reverse_each do |middleware| + middleware = middleware.call(self) if middleware.respond_to?(:call) + next unless middleware + klass = middleware.shift + app = klass.new(app, *middleware) + end + app +end +</ruby> + +Remember, +build_app+ was called (by wrapped_app) in the last line of +Server#start+. +Here's how it looked like when we left: + +<ruby> +server.run wrapped_app, options, &blk +</ruby> + |