waistband 6.1.1 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2a8dfc890aa44ce948449adc7d58bab2f3094451
4
- data.tar.gz: 183af89784e63a51d6b83484136b545a620a7709
2
+ SHA256:
3
+ metadata.gz: 4518168ed8f8c82ae7a2f49c130c0820caa73055b8688cc0625f687b586801a9
4
+ data.tar.gz: e517b0570a28ad0d6d4bdf3dcd07662d5983a84185ddeeffc6759f244b09b82b
5
5
  SHA512:
6
- metadata.gz: 6920854fb526fb24b0ebac953b634d31905a9e0cabcaed4a6cfcf88960b3fa0880c8dbdd9b35cc1f165d0f231095ddfd4704838e673e8986dff840fd39bd1b4c
7
- data.tar.gz: a160cc5185218e52281e05323620f7b355bb3132560aa6b26ff7a1e81c19b5c8fcc1a99ea241fdf94b9ad15db837311e09416f7d3725ec5394a6b51c34d8c6b4
6
+ metadata.gz: bb73344c8aa5e5432a3c66ef88bba5ed4feeca510ab88d8084ecf8636cac9c06751e58b0595750eff0215378b8d1eeb7c12074443f148d4969d83f951b64abb9
7
+ data.tar.gz: bf1eda0b6660ee7a2294ffe90e70759c44c2b4335a7df80d26df53a211bbc45f5cad5b304ee3de1faa5bfe85b910dca81208d92f805633621ab34de22b22fca1
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [6.2.0] - 2019-10-30
8
+ ### Added
9
+ - `#update`
10
+
11
+ ## [6.1.1] - 2019-10-29
12
+ ### Bug fix
13
+ - Ensure configuration loaded via YAML is compatible with `elasticsearch-transport`
14
+
7
15
  ## [6.1.0] - 2019-05-10
8
16
  ### Added
9
17
  - `#delete_by_query`
data/README.md CHANGED
@@ -185,6 +185,11 @@ index.find('my_data') # => {"important"=>true, "valuable"=>{"always"=>true}}
185
185
  # reading with all the internal data
186
186
  index.read('my_data') # => {'_id' => '123123', '_source' => {"important"=>true, "valuable"=>{"always"=>true}}, ...}
187
187
 
188
+ # partial updating
189
+ index.save('my_data', {'important' => true, 'valuable' => {'always' => true}}) # => true
190
+ index.update('my_data', {'important' => false }) # => true
191
+ index.read('my_data') # => {'_id' => '123123', '_source' => {"important"=>false, "valuable"=>{"always"=>true}}, ...}
192
+
188
193
  # deleting
189
194
  index.destroy('my_data') # => "{\"ok\":true,\"found\":true,\"_index\":\"search\",\"_type\":\"search\",\"_id\":\"my_data\",\"_version\":2}"
190
195
 
@@ -53,11 +53,10 @@ module Waistband
53
53
 
54
54
  private
55
55
 
56
- def hosts
57
- @hosts ||= @servers.map do |server_name, config|
58
- config
59
- end
56
+ def hosts
57
+ @hosts ||= @servers.map do |server_name, config|
58
+ config.each_with_object({}) { |(key, value), obj| obj[key.to_sym] = value }
60
59
  end
61
-
60
+ end
62
61
  end
63
62
  end
@@ -15,6 +15,7 @@ module Waistband
15
15
  class IndexNotFound < StandardError; end
16
16
  class NoSearchHits < StandardError; end
17
17
  class UnableToSave < StandardError; end
18
+ class UnableToUpdate < StandardError; end
18
19
 
19
20
  end
20
21
  end
@@ -132,6 +132,40 @@ module Waistband
132
132
  false
133
133
  end
134
134
 
135
+ def update!(*args)
136
+ check_permission!('write')
137
+
138
+ body_hash = args.extract_options!
139
+ id = args.first
140
+ _type = body_hash.delete(:_type) || body_hash.delete('_type') || default_type_name
141
+
142
+ # map everything to strings if need be
143
+ body_hash = stringify_all(body_hash) if @stringify
144
+
145
+ verify_body_size(config_name, _type, id, body_hash)
146
+
147
+ body_hash = { doc: body_hash }
148
+
149
+ saved = client.update(
150
+ index: config_name,
151
+ type: _type,
152
+ id: id,
153
+ body: body_hash
154
+ )
155
+
156
+ unless saved['_id'].present?
157
+ raise ::Waistband::Errors::UnableToUpdate.new("Unable to update to index: #{config_name}, type: #{_type}, id: #{id}: result: #{saved}")
158
+ end
159
+
160
+ saved
161
+ end
162
+
163
+ def update(*args)
164
+ update!(*args)
165
+ rescue ::Waistband::Errors::UnableToUpdate
166
+ false
167
+ end
168
+
135
169
  def find(id, options = {})
136
170
  find!(id, options)
137
171
  rescue Elasticsearch::Transport::Transport::Errors::NotFound
@@ -1,3 +1,3 @@
1
1
  module Waistband
2
- VERSION = "6.1.1"
2
+ VERSION = "6.2.0"
3
3
  end
@@ -48,6 +48,10 @@ describe Waistband::Configuration do
48
48
  end
49
49
 
50
50
  describe 'hosts' do
51
+ it "formats host Hashes to use Symbolized keys" do
52
+ keys = config.client.send(:hosts).first.keys
53
+ expect(keys.first).to be_a(Symbol)
54
+ end
51
55
 
52
56
  it "returns array of all available servers' configs" do
53
57
  hosts = config.client.send(:hosts)
@@ -55,9 +59,9 @@ describe Waistband::Configuration do
55
59
  expect(hosts.size).to eql 2
56
60
 
57
61
  hosts.each_with_index do |server, i|
58
- expect(server['host']).to match(/127\.0\.0\.1|localhost/)
59
- expect(server['port']).to eql 9200
60
- expect(server['protocol']).to eql 'http'
62
+ expect(server[:host]).to match(/127\.0\.0\.1|localhost/)
63
+ expect(server[:port]).to eql 9200
64
+ expect(server[:protocol]).to eql 'http'
61
65
  end
62
66
  end
63
67
 
@@ -71,8 +71,8 @@ describe Waistband::Index do
71
71
 
72
72
  it "correctly sets hosts" do
73
73
  expect(index.client.send(:hosts)).to eql([
74
- {"host" => "localhost", "port" => 9200, "protocol" => "http"},
75
- {"host" => "127.0.0.1", "port" => 9200, "protocol" => "http"}
74
+ {host: "localhost", port: 9200, protocol: "http"},
75
+ {host: "127.0.0.1", port: 9200, protocol: "http"}
76
76
  ])
77
77
  end
78
78
 
@@ -92,7 +92,6 @@ describe Waistband::Index do
92
92
  end
93
93
 
94
94
  describe "storing" do
95
-
96
95
  it "stores data" do
97
96
  expect(index.save('__test_write', {'ok' => 'yeah'})).to be_present
98
97
  expect(index.read('__test_write')).to eql({
@@ -105,6 +104,19 @@ describe Waistband::Index do
105
104
  })
106
105
  end
107
106
 
107
+ it "can partially updates documents" do
108
+ expect(index.save('__test_write', {'ok' => 'yeah', 'not_ok' => 'yeah'})).to be_present
109
+ expect(index.update('__test_write', {'not_ok' => 'no'})).to be_present
110
+ expect(index.read('__test_write')).to eql({
111
+ '_id' => '__test_write',
112
+ '_index' => 'events_test',
113
+ '_source' => {'ok' => 'yeah', 'not_ok' => 'no'},
114
+ '_type' => 'event',
115
+ '_version' => 2,
116
+ 'found' => true
117
+ })
118
+ end
119
+
108
120
  it "data is stringified" do
109
121
  index.save('__test_write', attrs)
110
122
  expect(index.read('__test_write')[:_source]).to eql({"ok"=>"{\"yeah\"=>true}"})
@@ -8,11 +8,13 @@ describe Waistband::Index do
8
8
  it "grabs connection data from the index's settings" do
9
9
  expect(client).to be_a(::Waistband::Client)
10
10
  expect(client.connection).to be_a(::Elasticsearch::Transport::Client)
11
- expect(client.instance_variable_get('@servers')).to eql({"server1"=>{"host"=>"127.0.0.1", "port"=>9200, "protocol"=>"http"}})
11
+ expect(client.instance_variable_get('@servers'))
12
+ .to eql({"server1"=>{"host"=>"127.0.0.1", "port"=>9200, "protocol"=>"http"}})
12
13
  end
13
14
 
14
15
  it "correctly sets hosts" do
15
- expect(client.send(:config_hash)[:hosts]).to eql([{"host"=>"127.0.0.1", "port"=>9200, "protocol"=>"http"}])
16
+ expect(client.send(:config_hash)[:hosts])
17
+ .to eql([{host: "127.0.0.1", port: 9200, protocol: "http"}])
16
18
  end
17
19
 
18
20
  it "exposes servers correctly" do
@@ -22,7 +24,7 @@ describe Waistband::Index do
22
24
  it "works" do
23
25
  index.delete
24
26
  index.create
25
- saved = index.save('testing123', {ok: 'yeah'})
27
+ index.save('testing123', {ok: 'yeah'})
26
28
  index.refresh
27
29
  data = index.read('testing123')
28
30
  expect(data['_source']['ok']).to eql 'yeah'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waistband
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.1
4
+ version: 6.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Jairala
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-29 00:00:00.000000000 Z
11
+ date: 2019-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -149,8 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  - !ruby/object:Gem::Version
150
150
  version: '0'
151
151
  requirements: []
152
- rubyforge_project:
153
- rubygems_version: 2.5.2
152
+ rubygems_version: 3.0.6
154
153
  signing_key:
155
154
  specification_version: 4
156
155
  summary: Configuration and sensible defaults for ElasticSearch on Ruby