lib/elasticsearch/transport/client.rb in elasticsearch-transport-1.0.7 vs lib/elasticsearch/transport/client.rb in elasticsearch-transport-1.0.9
- old
+ new
@@ -126,40 +126,40 @@
# @raise [ArgumentError]
#
# @api private
#
def __extract_hosts(hosts_config, options={})
- if hosts_config.respond_to?(:to_hash)
+ if hosts_config.is_a?(Hash)
hosts = [ hosts_config ]
else
if hosts_config.is_a?(String) && hosts_config.include?(',')
hosts = hosts_config.split(/\s*,\s*/)
else
hosts = Array(hosts_config)
end
+ end
- hosts.map! do |host|
- case host
- when String
- if host =~ /^[a-z]+\:\/\//
- uri = URI.parse(host)
- { :scheme => uri.scheme, :user => uri.user, :password => uri.password, :host => uri.host, :path => uri.path, :port => uri.port.to_s }
- else
- host, port = host.split(':')
- { :host => host, :port => port }
- end
- when URI
- { :scheme => host.scheme, :user => host.user, :password => host.password, :host => host.host, :path => host.path, :port => host.port.to_s }
- when Hash
- host
+ result = hosts.map do |host|
+ case host
+ when String
+ if host =~ /^[a-z]+\:\/\//
+ uri = URI.parse(host)
+ { :scheme => uri.scheme, :user => uri.user, :password => uri.password, :host => uri.host, :path => uri.path, :port => uri.port.to_s }
else
- raise ArgumentError, "Please pass host as a String, URI or Hash -- #{host.class} given."
+ host, port = host.split(':')
+ { :host => host, :port => port }
end
+ when URI
+ { :scheme => host.scheme, :user => host.user, :password => host.password, :host => host.host, :path => host.path, :port => host.port.to_s }
+ when Hash
+ host
+ else
+ raise ArgumentError, "Please pass host as a String, URI or Hash -- #{host.class} given."
end
end
- hosts.shuffle! if options[:randomize_hosts]
- hosts
+ result.shuffle! if options[:randomize_hosts]
+ result
end
# Auto-detect the best adapter (HTTP "driver") available, based on libraries
# loaded by the user, preferring those with persistent connections
# ("keep-alive") by default