lib/desi/index_manager.rb in desi-0.4.0 vs lib/desi/index_manager.rb in desi-0.5.0

- old
+ new

@@ -1,8 +1,9 @@ # encoding: utf-8 require "desi/http_client" +require "desi/configuration" module Desi # Performs some simple index-related operations on a local or distance # Elastic Search cluster @@ -31,11 +32,11 @@ # Initializes a Desi::IndexManager instance # # @param [#to_hash] opts Hash of extra opts # - # @option opts [#to_s] :host ('http://127.0.0.1:9200') Host to manage indices for + # @option opts [#to_s] :host ('http://localhost:9200') Host to manage indices for # @option opts [Boolean] :verbose (nil) Whether to output the actions' result # on STDOUT # @option opts [#new] :http_client_factory (Desi::HttpClient) HTTP transport class # to use # @@ -43,11 +44,11 @@ # to #get and #delete # @return [void] # # @api public def initialize(opts = {}) - @host = to_uri(opts.fetch(:host, 'http://127.0.0.1:9200')) + @host = to_uri(opts.fetch(:host) { Desi.configuration.server }) @verbose = opts[:verbose] @outputter = opts.fetch(:outputter, Kernel) @client = opts.fetch(:http_client_factory, Desi::HttpClient).new(@host) end @@ -135,10 +136,10 @@ Index.new(k, v) if k =~ pattern }.compact end def to_uri(host_string) - scheme, host, port = ['http', '127.0.0.1', 9200] + scheme, host, port = ['http', 'localhost', 9200] %r{(?<scheme>(https?|))(?:\:\/\/|)(?<host>[^:]*?):?(?<port>\d*)/?$}.match(host_string.to_s) do |m| scheme = m[:scheme] unless m[:scheme].empty? host = m[:host] unless m[:host].empty? port = m[:port] unless m[:port].empty?