elastic_search_framework 2.2.0 → 2.3.0
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cb32d84eb11d74afb4b32b129fc7b6fb3654714ffc8cc68a22837641437c92a
|
4
|
+
data.tar.gz: bddf4744857f12fcb44272813c6c644b373c32029c46ae470f17b239e3279762
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7606703ced3bd3bf8e47312e408a687c45fdee2362a19d92cd007782b2748d9b1fc5bfa8d998d67040884697236c976d7c128eb4021173a758a713b9b2e725d
|
7
|
+
data.tar.gz: 721beafb796c691392c037b4651f3f51ea29ab24ce4d1b047fb8ade55887356c15cd4fb85af807125364382c5c387467ef466c23526f037ae06b6378354b287b
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module ElasticSearchFramework
|
2
2
|
class Repository
|
3
3
|
|
4
|
-
def set(index:, entity:, type: 'default')
|
5
|
-
uri = URI("#{host}/#{index.full_name}/#{type.downcase}/#{get_id_value(index: index, entity: entity)}")
|
4
|
+
def set(index:, entity:, type: 'default', op_type: 'index')
|
5
|
+
uri = URI("#{host}/#{index.full_name}/#{type.downcase}/#{get_id_value(index: index, entity: entity)}?op_type=#{op_type}")
|
6
6
|
hash = hash_helper.to_hash(entity)
|
7
7
|
|
8
8
|
request = Net::HTTP::Put.new(uri.request_uri)
|
@@ -13,12 +13,15 @@ module ElasticSearchFramework
|
|
13
13
|
client.request(request)
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
if valid_response?(response.code)
|
17
|
+
return true
|
18
|
+
elsif op_type == 'create' && Integer(response.code) == 409
|
19
|
+
return true
|
20
|
+
else
|
17
21
|
raise ElasticSearchFramework::Exceptions::IndexError.new(
|
18
22
|
"An error occurred setting an index document. Response: #{response.body} | Code: #{response.code}"
|
19
23
|
)
|
20
24
|
end
|
21
|
-
return true
|
22
25
|
end
|
23
26
|
|
24
27
|
def get(index:, id:, type: 'default')
|
@@ -63,22 +63,40 @@ RSpec.describe ElasticSearchFramework::Repository do
|
|
63
63
|
ExampleIndexWithId.create
|
64
64
|
end
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
66
|
+
context 'PUT with op_type: index' do
|
67
|
+
it 'should create, read and delete an index document' do
|
68
|
+
subject.set(index: ExampleIndex, entity: item1)
|
69
|
+
subject.set(index: ExampleIndex, entity: item1.tap { |i| i.timestamp += 100 })
|
70
|
+
subject.set(index: ExampleIndex, entity: item1.tap { |i| i.timestamp += 100 }, op_type: 'index')
|
71
|
+
subject.set(index: ExampleIndex, entity: item2)
|
72
|
+
subject.set(index: ExampleIndex, entity: item5)
|
73
|
+
index_item1 = subject.get(index: ExampleIndex, id: item1.id)
|
74
|
+
expect(index_item1[:id]).to eq item1.id
|
75
|
+
expect(index_item1[:name]).to eq item1.name
|
76
|
+
expect(index_item1[:timestamp]).to eq item1.timestamp
|
77
|
+
expect(index_item1[:number]).to eq item1.number
|
78
|
+
index_item2 = subject.get(index: ExampleIndex, id: item2.id)
|
79
|
+
expect(index_item2[:id]).to eq item2.id
|
80
|
+
expect(index_item2[:name]).to eq item2.name
|
81
|
+
expect(index_item2[:timestamp]).to eq item2.timestamp
|
82
|
+
expect(index_item2[:number]).to eq item2.number
|
83
|
+
subject.drop(index: ExampleIndex, id: item1.id)
|
84
|
+
expect(subject.get(index: ExampleIndex, id: item1.id)).to be_nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'PUT with op_type: create' do
|
89
|
+
let!(:original_timestamp) { item1.timestamp }
|
90
|
+
|
91
|
+
it 'should not update item' do
|
92
|
+
subject.set(index: ExampleIndex, entity: item1)
|
93
|
+
subject.set(index: ExampleIndex, entity: item1.tap { |i| i.timestamp += 100 }, op_type: 'create')
|
94
|
+
index_item1 = subject.get(index: ExampleIndex, id: item1.id)
|
95
|
+
expect(index_item1[:id]).to eq item1.id
|
96
|
+
expect(index_item1[:name]).to eq item1.name
|
97
|
+
expect(index_item1[:timestamp]).to eq original_timestamp
|
98
|
+
expect(index_item1[:number]).to eq item1.number
|
99
|
+
end
|
82
100
|
end
|
83
101
|
|
84
102
|
after do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic_search_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vaughanbrittonsage
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
153
|
- !ruby/object:Gem::Version
|
154
154
|
version: '0'
|
155
155
|
requirements: []
|
156
|
-
rubygems_version: 3.0.
|
156
|
+
rubygems_version: 3.0.8
|
157
157
|
signing_key:
|
158
158
|
specification_version: 4
|
159
159
|
summary: A lightweight framework to for working with elastic search.
|