Skip to content

Commit

Permalink
Implement Array parameters in Command to pass multiple requires.
Browse files Browse the repository at this point in the history
Do not set threaded or no_epoll if backend do not implement it.
  • Loading branch information
macournoyer committed Jul 18, 2008
1 parent a8ed858 commit 23b7931
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
8 changes: 5 additions & 3 deletions lib/thin/command.rb
Expand Up @@ -34,12 +34,14 @@ def run
# Turn into a runnable shell command
def shellify
shellified_options = @options.inject([]) do |args, (name, value)|
args << case value
case value
when NilClass,
TrueClass then "--#{name}"
TrueClass then args << "--#{name}"
when FalseClass
else "--#{name.to_s.tr('_', '-')}=#{value.inspect}"
when Array then value.each { |v| args << "--#{name}=#{v.inspect}" }
else args << "--#{name.to_s.tr('_', '-')}=#{value.inspect}"
end
args
end

raise ArgumentError, "Path to thin script can't be found, set Command.script" unless self.class.script
Expand Down
4 changes: 2 additions & 2 deletions lib/thin/controllers/controller.rb
Expand Up @@ -48,8 +48,8 @@ def start
server.timeout = @options[:timeout]
server.maximum_connections = @options[:max_conns]
server.maximum_persistent_connections = @options[:max_persistent_conns]
server.threaded = @options[:threaded]
server.no_epoll = @options[:no_epoll]
server.threaded = @options[:threaded] if server.backend.respond_to?(:threaded)
server.no_epoll = @options[:no_epoll] if server.backend.respond_to?(:no_epoll)

# Detach the process, after this line the current process returns
server.daemonize if @options[:daemonize]
Expand Down
6 changes: 3 additions & 3 deletions lib/thin/runner.rb
Expand Up @@ -41,7 +41,7 @@ def initialize(argv)
:pid => 'tmp/pids/thin.pid',
:max_conns => Server::DEFAULT_MAXIMUM_CONNECTIONS,
:max_persistent_conns => Server::DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS,
:requires => []
:require => []
}

parse!
Expand Down Expand Up @@ -117,7 +117,7 @@ def parser
opts.separator ""
opts.separator "Common options:"

opts.on_tail("-r", "--require FILE", "require the library") { |file| @options[:requires] << file }
opts.on_tail("-r", "--require FILE", "require the library") { |file| @options[:require] << file }
opts.on_tail("-D", "--debug", "Set debbuging on") { @options[:debug] = true }
opts.on_tail("-V", "--trace", "Set tracing on (log raw request/response)") { @options[:trace] = true }
opts.on_tail("-h", "--help", "Show this message") { puts opts; exit }
Expand Down Expand Up @@ -158,7 +158,7 @@ def run_command
# relative to this one.
Dir.chdir(@options[:chdir]) unless CONFIGLESS_COMMANDS.include?(@command)

@options[:requires].each { |r| ruby_require r }
@options[:require].each { |r| ruby_require r }
Logging.debug = @options[:debug]
Logging.trace = @options[:trace]

Expand Down
4 changes: 3 additions & 1 deletion lib/thin/server.rb
Expand Up @@ -91,6 +91,8 @@ class Server
def initialize(*args, &block)
host, port, options = DEFAULT_HOST, DEFAULT_PORT, {}

# Guess each parameter by its type so they can be
# received in any order.
args.each do |arg|
case arg
when Fixnum, /^\d+$/ then port = arg.to_i
Expand All @@ -105,7 +107,7 @@ def initialize(*args, &block)
@backend = select_backend(host, port, options)

load_cgi_multipart_eof_fix

@backend.server = self

# Set defaults
Expand Down
8 changes: 7 additions & 1 deletion spec/command_spec.rb
Expand Up @@ -3,12 +3,18 @@
describe Command do
before do
Command.script = 'thin'
@command = Command.new(:start, :port => 3000, :daemonize => true, :log => 'hi.log')
@command = Command.new(:start, :port => 3000, :daemonize => true, :log => 'hi.log',
:require => %w(rubygems thin))
end

it 'should shellify command' do
out = @command.shellify
out.should include('--port=3000', '--daemonize', '--log="hi.log"', 'thin start --')
out.should_not include('--pid')
end

it 'should shellify Array argument to multiple parameters' do
out = @command.shellify
out.should include('--require="rubygems"', '--require="thin"')
end
end
2 changes: 1 addition & 1 deletion spec/runner_spec.rb
Expand Up @@ -80,7 +80,7 @@

it "should remember requires" do
runner = Runner.new(%w(start -r rubygems -r thin))
runner.options[:requires].should == %w(rubygems thin)
runner.options[:require].should == %w(rubygems thin)
end

it "should remember debug options" do
Expand Down

0 comments on commit 23b7931

Please sign in to comment.