Class: ElasticSearch::AbstractClient
- Inherits:
-
Object
- Object
- ElasticSearch::AbstractClient
- Defined in:
- lib/elasticsearch/client/abstract_client.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULTS =
{ :transport => ElasticSearch::Transport::HTTP }.freeze
Instance Method Summary collapse
- #connect! ⇒ Object
- #current_server ⇒ Object
- #disconnect! ⇒ Object
- #execute(method_name, *args) ⇒ Object
- #extract_server_list_and_defaults(servers_or_url) ⇒ Object
-
#initialize(servers_or_url, options = {}) ⇒ AbstractClient
constructor
A new instance of AbstractClient.
- #inspect ⇒ Object
- #servers ⇒ Object
Constructor Details
#initialize(servers_or_url, options = {}) ⇒ AbstractClient
Returns a new instance of AbstractClient.
10 11 12 13 14 |
# File 'lib/elasticsearch/client/abstract_client.rb', line 10 def initialize(servers_or_url, ={}) @options = DEFAULTS.merge() @server_list, @default_index, @default_type = extract_server_list_and_defaults(servers_or_url) @current_server = @server_list.first end |
Instance Method Details
#connect! ⇒ Object
39 40 41 42 |
# File 'lib/elasticsearch/client/abstract_client.rb', line 39 def connect! @connection = @options[:transport].new(@current_server, @options) @connection.connect! end |
#current_server ⇒ Object
27 28 29 |
# File 'lib/elasticsearch/client/abstract_client.rb', line 27 def current_server @current_server end |
#disconnect! ⇒ Object
44 45 46 47 48 |
# File 'lib/elasticsearch/client/abstract_client.rb', line 44 def disconnect! @connection.close rescue nil @connection = nil @current_server = nil end |
#execute(method_name, *args) ⇒ Object
50 51 52 53 |
# File 'lib/elasticsearch/client/abstract_client.rb', line 50 def execute(method_name, *args) connect! unless @connection @connection.send(method_name, *args) end |
#extract_server_list_and_defaults(servers_or_url) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/elasticsearch/client/abstract_client.rb', line 16 def extract_server_list_and_defaults(servers_or_url) default_index = default_type = nil servers = Array(servers_or_url).collect do |server| uri = URI.parse(server) _, default_index, default_type = uri.path.split("/") uri.path = "" # is this expected behavior of URI? may be dangerous to rely on uri.to_s end [servers, default_index, default_type] end |
#inspect ⇒ Object
35 36 37 |
# File 'lib/elasticsearch/client/abstract_client.rb', line 35 def inspect "<#{self.class} @current_server=#{@current_server} @server_list=#{@server_list.inspect} @options=#{@options.inspect}>" end |
#servers ⇒ Object
31 32 33 |
# File 'lib/elasticsearch/client/abstract_client.rb', line 31 def servers @server_list end |