elasticsearch-transport/lib/elasticsearch/transport/client.rb
# Normalizes and returns hosts configuration.
#
# Arrayifies the `hosts_config` argument and extracts `host` and `port` info from strings.
# Performs shuffling when the `randomize_hosts` option is set.
#
# TODO: Refactor, so it's available in Elasticsearch::Transport::Base as well
#
# @return [Array<Hash>]
# @raise  [ArgumentError]
#
# @api private
#
Normalizes and returns hosts configuration.

Refactor, so it's available in Elasticsearch::Transport::Base as well
Normalizes and returns hosts configuration . Refactor so it ' s available in Elasticsearch :: Transport :: Base as well
def __extract_hosts(hosts_config, options={})
        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
        result = hosts.map do |host|
          host_parts = 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 }
              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 }
            when Hash
              host
            else
              raise ArgumentError, "Please pass host as a String, URI or Hash -- {host.class} given."
            end
          host_parts[:port] = host_parts[:port].to_i unless host_parts[:port].nil?
          host_parts.select { |k,v| [:scheme, :port, :user, :password].include?(k) }.each do |k,v|
            @arguments[:http][k] ||= v
          end
           Remove the trailing slash
          host_parts[:path] = host_parts[:path].chomp('/') if host_parts[:path]
          host_parts
        end
        result.shuffle! if options[:randomize_hosts]
        result
      end
def __extract_hosts ( hosts_config , options = { } ) 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 result = hosts . map do | host | host_parts = 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 } 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 } when Hash host else raise ArgumentError , "Please pass host as a String, URI or Hash -- #{host.class} given." end host_parts [ :port ] = host_parts [ :port ] . to_i unless host_parts [ :port ] . nil? host_parts . select { | k , v | [ :scheme , :port , :user , :password ] . include? ( k ) } . each do | k , v | @arguments [ :http ] [ k ] ||= v end host_parts [ :path ] = host_parts [ :path ] . chomp ( '/' ) if host_parts [ :path ] host_parts end result . shuffle! if options [ :randomize_hosts ] result end
Normalizes and returns hosts configuration.
Normalizes and returns hosts configuration .
# Transfer the selected host parts such as authentication credentials to `options`, # so we can re-use them when reloading connections # # Remove the trailing slash
None
Array<Hash>
None
hosts_config
<not_specific>
options
<not_specific>
api
None