es 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/es/client.rb +10 -5
- data/lib/es/version.rb +1 -1
- data/spec/es/client_spec.rb +12 -10
- metadata +2 -2
data/lib/es/client.rb
CHANGED
@@ -10,7 +10,7 @@ module ES
|
|
10
10
|
|
11
11
|
def bulk(requests, path = nil)
|
12
12
|
serialized = requests.map do |r|
|
13
|
-
|
13
|
+
serialize(r) + "\n"
|
14
14
|
end.join('')
|
15
15
|
|
16
16
|
response = @client.bulk(serialized, path)
|
@@ -24,25 +24,25 @@ module ES
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def index(path, data)
|
27
|
-
serialized =
|
27
|
+
serialized = serialize(data)
|
28
28
|
response = @client.index(path, serialized)
|
29
29
|
@dumper.load(response)
|
30
30
|
end
|
31
31
|
|
32
32
|
def search(path, data)
|
33
|
-
serialized =
|
33
|
+
serialized = serialize(data)
|
34
34
|
response = @client.search(path, serialized)
|
35
35
|
@dumper.load(response)
|
36
36
|
end
|
37
37
|
|
38
38
|
def update(path, data)
|
39
|
-
serialized =
|
39
|
+
serialized = serialize(data)
|
40
40
|
response = @client.update(path, serialized)
|
41
41
|
@dumper.load(response)
|
42
42
|
end
|
43
43
|
|
44
44
|
def create_index(path, data)
|
45
|
-
serialized =
|
45
|
+
serialized = serialize(data)
|
46
46
|
response = @client.create_index(path, serialized)
|
47
47
|
@dumper.load(response)
|
48
48
|
end
|
@@ -51,5 +51,10 @@ module ES
|
|
51
51
|
response = @client.delete_index(path)
|
52
52
|
@dumper.load(response)
|
53
53
|
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def serialize(data)
|
57
|
+
@dumper.dump(data, mode: :compat)
|
58
|
+
end
|
54
59
|
end
|
55
60
|
end
|
data/lib/es/version.rb
CHANGED
data/spec/es/client_spec.rb
CHANGED
@@ -7,11 +7,13 @@ describe ES::Client do
|
|
7
7
|
subject { described_class.new(client: client) }
|
8
8
|
let(:raw_response) { '{}' }
|
9
9
|
let(:response) { {} }
|
10
|
+
let(:raw_data) { '{"a":1}' }
|
11
|
+
let(:data) { {a: 1} }
|
10
12
|
|
11
13
|
it 'serializes data for .create_index' do
|
12
|
-
client.should_receive(:create_index).with('index/1',
|
14
|
+
client.should_receive(:create_index).with('index/1', raw_data).and_return(raw_response)
|
13
15
|
|
14
|
-
subject.create_index('index/1',
|
16
|
+
subject.create_index('index/1', data).should == response
|
15
17
|
end
|
16
18
|
|
17
19
|
it 'serializes data for .delete_index' do
|
@@ -21,16 +23,16 @@ describe ES::Client do
|
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'serializes data for .bulk' do
|
24
|
-
requests = [1, 2, 3]
|
25
|
-
client.should_receive(:bulk).with("1\n2\n3\n", 'an_index').and_return(raw_response)
|
26
|
+
requests = [{a: 1}, 2, 3]
|
27
|
+
client.should_receive(:bulk).with("{\"a\":1}\n2\n3\n", 'an_index').and_return(raw_response)
|
26
28
|
|
27
29
|
subject.bulk(requests, 'an_index').should == response
|
28
30
|
end
|
29
31
|
|
30
32
|
it 'serializes data for .index' do
|
31
|
-
client.should_receive(:index).with('index/1',
|
33
|
+
client.should_receive(:index).with('index/1', raw_data).and_return(raw_response)
|
32
34
|
|
33
|
-
subject.index('index/1',
|
35
|
+
subject.index('index/1', data).should == response
|
34
36
|
end
|
35
37
|
|
36
38
|
it 'serializes data for .get' do
|
@@ -40,14 +42,14 @@ describe ES::Client do
|
|
40
42
|
end
|
41
43
|
|
42
44
|
it 'serializes data for .search' do
|
43
|
-
client.should_receive(:search).with('index/1',
|
45
|
+
client.should_receive(:search).with('index/1', raw_data).and_return(raw_response)
|
44
46
|
|
45
|
-
subject.search('index/1',
|
47
|
+
subject.search('index/1', data).should == response
|
46
48
|
end
|
47
49
|
|
48
50
|
it 'serializes data for .update' do
|
49
|
-
client.should_receive(:update).with('index/1',
|
51
|
+
client.should_receive(:update).with('index/1', raw_data).and_return(raw_response)
|
50
52
|
|
51
|
-
subject.update('index/1',
|
53
|
+
subject.update('index/1', data).should == response
|
52
54
|
end
|
53
55
|
end
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: es
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jan Suchal
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oj
|