diff --git a/lib/apache/master.rb b/lib/apache/master.rb index f03d38d..12daa5d 100644 --- a/lib/apache/master.rb +++ b/lib/apache/master.rb @@ -2,6 +2,12 @@ module Apache # 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. module Master + class << self + def listening_on + @listening_on ||= [] + end + end + # Build a module list. # Wraps around Modules.build def modules(*modules, &block) @@ -15,7 +21,14 @@ module Apache # Listen "1.2.3.4:80" # Listen "2.3.4.5:80" 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 alias :listen! :listen diff --git a/spec/apache/master_spec.rb b/spec/apache/master_spec.rb index f7bd8c0..ee77a14 100644 --- a/spec/apache/master_spec.rb +++ b/spec/apache/master_spec.rb @@ -1,4 +1,4 @@ -require 'apache/config' +require 'spec_helper' describe Apache::Master, "should provide basic helpers for configuration" do 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.to_a.should == [ 'Header set test test2', 'Header set "test3" "test4" test5=test6' ] 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