aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOscar Del Ben <info@oscardelben.com>2012-06-14 09:05:10 -0700
committerOscar Del Ben <info@oscardelben.com>2012-06-14 09:05:10 -0700
commit32664e746377113174cfe24ca3627e983c4b2972 (patch)
tree3726c629476d69469817dc52763450f7b7514d8b
parentf48c576fc85ab947e91ec93523951de4a2ff21bf (diff)
downloadrails-32664e746377113174cfe24ca3627e983c4b2972.tar.gz
rails-32664e746377113174cfe24ca3627e983c4b2972.tar.bz2
rails-32664e746377113174cfe24ca3627e983c4b2972.zip
Add server.run example
This is the last chapter before I go back and make sure the guide is complete/review
-rw-r--r--guides/source/initialization.textile45
1 files changed, 45 insertions, 0 deletions
diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile
index 1f94dc1419..0638bbed10 100644
--- a/guides/source/initialization.textile
+++ b/guides/source/initialization.textile
@@ -612,3 +612,48 @@ Here's how it looked like when we left:
server.run wrapped_app, options, &blk
</ruby>
+At this point, the implementation of +server.run+ will depend on the
+server you're using. For example, if you were using Mongrel, here's what
+the +run+ method would look like:
+
+<ruby>
+def self.run(app, options={})
+ server = ::Mongrel::HttpServer.new(
+ options[:Host] || '0.0.0.0',
+ options[:Port] || 8080,
+ options[:num_processors] || 950,
+ options[:throttle] || 0,
+ options[:timeout] || 60)
+ # Acts like Rack::URLMap, utilizing Mongrel's own path finding methods.
+ # Use is similar to #run, replacing the app argument with a hash of
+ # { path=>app, ... } or an instance of Rack::URLMap.
+ if options[:map]
+ if app.is_a? Hash
+ app.each do |path, appl|
+ path = '/'+path unless path[0] == ?/
+ server.register(path, Rack::Handler::Mongrel.new(appl))
+ end
+ elsif app.is_a? URLMap
+ app.instance_variable_get(:@mapping).each do |(host, path, appl)|
+ next if !host.nil? && !options[:Host].nil? && options[:Host] != host
+ path = '/'+path unless path[0] == ?/
+ server.register(path, Rack::Handler::Mongrel.new(appl))
+ end
+ else
+ raise ArgumentError, "first argument should be a Hash or URLMap"
+ end
+ else
+ server.register('/', Rack::Handler::Mongrel.new(app))
+ end
+ yield server if block_given?
+ server.run.join
+end
+</ruby>
+
+We wont dig into the server configuration itself, but this is
+the last piece of our journey in the Rails initialization process.
+
+This high level overview will help you understand when you code is
+executed and how, and overall become a better Rails developer. If you
+still want to know more, the Rails source code itself is probably the
+best place to go next.