Skip to content

Commit ed49cb9

Browse files
committed
[MODEL] Extract MyModel.client into a separate module
Example: -------- > Article.client( Elasticsearch::Client.new log: true ); > Article.search('foo').results.map(&:_source).map(&:title) 2013-11-08 20:29:28 +0100: GET http://localhost:9200/articles/_search?q=foo [status:200, request:0.004s, query:0.001s] 2013-11-08 20:29:28 +0100: < {"took":1,"timed_out":false, ...} => ["Foo", "Bar"]
1 parent 081c39f commit ed49cb9

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

elasticsearch-model/lib/elasticsearch/model.rb

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
require 'elasticsearch/model/support/forwardable'
88

9+
require 'elasticsearch/model/client'
10+
911
require 'elasticsearch/model/adapter'
1012
require 'elasticsearch/model/adapters/default'
1113
require 'elasticsearch/model/adapters/active_record'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Elasticsearch
2+
module Model
3+
module Client
4+
5+
module ClassMethods
6+
7+
# Get or set the client
8+
#
9+
def client client=nil
10+
@client = client || @client || Elasticsearch::Client.new
11+
end
12+
end
13+
14+
end
15+
end
16+
end

elasticsearch-model/lib/elasticsearch/model/searching.rb

-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ def search(query_or_payload, options={})
99
Response::Response.new(self, response)
1010
end
1111

12-
def client
13-
@client ||= Elasticsearch::Client.new
14-
end
15-
1612
end
1713

1814
end

0 commit comments

Comments
 (0)