prevent multiple listen statements for the same adapter within one config cycle

This commit is contained in:
John Bintz 2011-09-27 15:38:12 -04:00
parent 495c88ff77
commit dfe3e6784b
2 changed files with 27 additions and 2 deletions

View File

@ -2,6 +2,12 @@ module Apache
# Options that aren't specific to a particular purpose go here. Once enough like methods for a # Options that aren't specific to a particular purpose go here. Once enough like methods for a
# particular purpose exist, break them out into a separate module. # particular purpose exist, break them out into a separate module.
module Master module Master
class << self
def listening_on
@listening_on ||= []
end
end
# Build a module list. # Build a module list.
# Wraps around Modules.build # Wraps around Modules.build
def modules(*modules, &block) def modules(*modules, &block)
@ -15,7 +21,14 @@ module Apache
# Listen "1.2.3.4:80" # Listen "1.2.3.4:80"
# Listen "2.3.4.5:80" # Listen "2.3.4.5:80"
def listen(*opt) def listen(*opt)
opt.each { |adapter| self << "Listen #{adapter.quoteize}" } opt.collect(&:quoteize).each do |adapter|
if !Apache::Master.listening_on.include?(adapter)
self << "Listen #{adapter}"
Apache::Master.listening_on << adapter
else
$stderr.puts "Multiple Listens for #{adapter}".foreground(:red)
end
end
end end
alias :listen! :listen alias :listen! :listen

View File

@ -1,4 +1,4 @@
require 'apache/config' require 'spec_helper'
describe Apache::Master, "should provide basic helpers for configuration" do describe Apache::Master, "should provide basic helpers for configuration" do
let(:apache) { Apache::Config } let(:apache) { Apache::Config }
@ -81,4 +81,16 @@ describe Apache::Master, "should provide basic helpers for configuration" do
apache.set_header 'test3' => [ 'test4', "test5=test6" ] apache.set_header 'test3' => [ 'test4', "test5=test6" ]
apache.to_a.should == [ 'Header set test test2', 'Header set "test3" "test4" test5=test6' ] apache.to_a.should == [ 'Header set test test2', 'Header set "test3" "test4" test5=test6' ]
end end
describe '#listen' do
it 'should not allow one to listen twice on the same interface' do
apache.listen "one"
apache.listen "two"
apache.listen "one"
apache.to_a.should == [ 'Listen "one"', 'Listen "two"' ]
Apache::Master.listening_on.should == %w{"one" "two"}
end
end
end end