-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Hey @codereading/readers
as per the [discussion] https://github.com/codereading/HQ/issues/8 in HQ re: structure of codereading sessions, it seems a documented walkthrough of rack would be useful.
So perhaps we can walkthrough rack asking questions as we go along.
So to get thing rolling ill start.
Assuming we are using the rackup command to load an app
i.e.
rackup lobster.ru
then the first place to look would be bin/rackup.ru
where we discover it simply calls
Rack::Server.start
module Rack
class Server
# Start a new rack server (like running rackup). This will parse ARGV and
# provide standard ARGV rackup options, defaulting to load 'config.ru'.
#
# Providing an options hash will prevent ARGV parsing and will not include
# any default options.
def self.start(options = nil)
new(options).start
end
attr_writer :options
def initialize(options = nil)
@options = options
@app = options[:app] if options && options[:app]
end
def options
@options ||= parse_options(ARGV)
end
....
end
As per the comments, if we dont pass an options hash to Server.start, Rack will parse ARGV for arguments (in this case we passed lobster.rb on the command line). The problem is I don't see how the code above would do this.
start calls new passing nil as the options argument. Within initialize nil is assigned to @options. Any reference to "options" will always refer to the argument so the method
def options
@options ||= parse_options(ARGV)
end
will never get called. So how does rack call parse_options(ARGV) ???