diff options
author | Tyler Cloke <tylercloke@gmail.com> | 2016-04-14 12:45:08 -0700 |
---|---|---|
committer | Tyler Cloke <tylercloke@gmail.com> | 2016-04-14 13:23:36 -0700 |
commit | 344677bbf7028acc41226b39f9ca639073b0c926 (patch) | |
tree | a8c83dc2969ce547c8093119474cecc02de3ea1f | |
parent | 799f727d01519de6e5249a724e3c9ac857031c7e (diff) | |
download | chef-zero-344677bbf7028acc41226b39f9ca639073b0c926.tar.gz |
Fix bugs related to Array vs Enumerator vs Port for options[:port/host].
[options[:port]].flatten does not do the right thing in the case that options[:port] is an Enumerator.
options[:host] is not always an Array (can be a String).
-rw-r--r-- | lib/chef_zero/server.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb index dc4fc0f..31c8baa 100644 --- a/lib/chef_zero/server.rb +++ b/lib/chef_zero/server.rb @@ -142,6 +142,7 @@ module ChefZero def port if @port @port + # If options[:port] is not an Array or an Enumerable, it is just an Integer. elsif !options[:port].respond_to?(:each) options[:port] else @@ -164,10 +165,11 @@ module ChefZero # def url sch = @options[:ssl] ? 'https' : 'http' - @url ||= if @options[:host].first.include?(':') - URI("#{sch}://[#{@options[:host].first}]:#{port}").to_s + hosts = Array(@options[:host]) + @url ||= if hosts.first.include?(':') + URI("#{sch}://[#{hosts.first}]:#{port}").to_s else - URI("#{sch}://#{@options[:host].first}:#{port}").to_s + URI("#{sch}://#{hosts.first}:#{port}").to_s end end @@ -292,8 +294,10 @@ module ChefZero @server.mount('/', Rack::Handler::WEBrick, app) # Pick a port - [options[:port]].flatten.each do |port| - if listen(options[:host], port) + # If options[:port] can be an Enumerator, an Array, or an Integer, + # we need something that can respond to .each (Enum and Array can already). + Array(options[:port]).each do |port| + if listen(Array(options[:host]), port) @port = port break end |