waistband 6.1.1 → 6.3.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: c663d799154fe793531c32248de60aa7942f34dbb54b0c04cf3373f9df652b0a
4
+ data.tar.gz: 9cc04d751ab8bf8911cc2c5925c805e7656a73bdc1a31e6092f873f14f025006
5
5
  SHA512:
6
- metadata.gz: 6920854fb526fb24b0ebac953b634d31905a9e0cabcaed4a6cfcf88960b3fa0880c8dbdd9b35cc1f165d0f231095ddfd4704838e673e8986dff840fd39bd1b4c
7
- data.tar.gz: a160cc5185218e52281e05323620f7b355bb3132560aa6b26ff7a1e81c19b5c8fcc1a99ea241fdf94b9ad15db837311e09416f7d3725ec5394a6b51c34d8c6b4
6
+ metadata.gz: 84ed774572d1aa01b615987c5bc8de1b8f6a55532307fc140a7a370652822b0c60e26ce7211e63cb0e5b83c713472f4988b8734f3382a7e6b43f3a9eb7bcbd4d
7
+ data.tar.gz: 2524de64e2658792fd7eb71efdd9e357f246d94bcfe9ebace8f6aeae98c8984c3d6bdd17491821ac3efd389a6873f5a306c8ec49253a6d4a2588f85a1360e47f
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0-p648
1
+ 3.1.4
data/CHANGELOG.md CHANGED
@@ -4,6 +4,18 @@ 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.3.0] - 2023-10-11
8
+ ### Added
9
+ - Support for Ruby 3.1 and its attendant Psych version
10
+
11
+ ## [6.2.0] - 2019-10-30
12
+ ### Added
13
+ - `#update`
14
+
15
+ ## [6.1.1] - 2019-10-29
16
+ ### Bug fix
17
+ - Ensure configuration loaded via YAML is compatible with `elasticsearch-transport`
18
+
7
19
  ## [6.1.0] - 2019-05-10
8
20
  ### Added
9
21
  - `#delete_by_query`
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'rspec', '~> 3.1.0'
7
- gem 'timecop', '~> 0.7.1'
7
+ gem 'timecop'
8
8
 
9
9
  unless ENV['ON_TRAVIS']
10
10
  gem 'byebug'
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
@@ -63,9 +63,9 @@ module Waistband
63
63
 
64
64
  def load_yml_with_erb(file)
65
65
  if defined?(ERB)
66
- YAML.load(ERB.new(File.read(file)).result)
66
+ YAML.safe_load(ERB.new(File.read(file)).result, aliases: true, permitted_classes: [Symbol])
67
67
  else
68
- YAML.load_file(file)
68
+ YAML.safe_load_file(file, aliases: true, permitted_classes: [Symbol])
69
69
  end
70
70
  end
71
71
 
@@ -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.3.0"
3
3
  end
@@ -25,11 +25,11 @@ describe Waistband::Configuration do
25
25
  end
26
26
 
27
27
  it "permits passing in an adapter to use to the client" do
28
- original_config = YAML.load_file(File.join(::Waistband.config.config_dir, 'waistband.yml'))['test']
28
+ original_config = YAML.safe_load_file(File.join(::Waistband.config.config_dir, 'waistband.yml'), aliases: true, permitted_classes: [Symbol])['test']
29
29
 
30
30
  expect(::Waistband.config.instance_variable_get('@adapter')).to be_nil
31
31
 
32
- expect(YAML).to receive(:load).and_return({'test' => original_config.merge({'adapter' => :net_http})}).at_least(:once)
32
+ expect(YAML).to receive(:safe_load).and_return({'test' => original_config.merge({'adapter' => :net_http})}).at_least(:once)
33
33
  ::Waistband.config.setup
34
34
  expect(::Waistband.config.instance_variable_get('@adapter')).to eql :net_http
35
35
  expect(::Waistband.client.transport.options[:adapter]).to eql :net_http
@@ -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,10 +92,9 @@ 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
- expect(index.read('__test_write')).to eql({
97
+ expect(index.read('__test_write')).to match a_hash_including({
99
98
  '_id' => '__test_write',
100
99
  '_index' => 'events_test',
101
100
  '_source' => {'ok' => 'yeah'},
@@ -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 match a_hash_including({
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'
data/waistband.gemspec CHANGED
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'activesupport'
21
+ spec.add_dependency 'activesupport', '< 7.1.0'
22
22
  spec.add_dependency 'elasticsearch', '~> 6.0'
23
23
  spec.add_dependency 'json'
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "bundler", "~> 2.4"
26
26
  spec.add_development_dependency "rake", "~> 10.3"
27
27
  end
metadata CHANGED
@@ -1,29 +1,29 @@
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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Jairala
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-29 00:00:00.000000000 Z
11
+ date: 2023-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "<"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 7.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "<"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 7.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: elasticsearch
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.3'
61
+ version: '2.4'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.3'
68
+ version: '2.4'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -134,7 +134,7 @@ homepage: https://github.com/taskrabbit/waistband
134
134
  licenses:
135
135
  - MIT
136
136
  metadata: {}
137
- post_install_message:
137
+ post_install_message:
138
138
  rdoc_options: []
139
139
  require_paths:
140
140
  - lib
@@ -149,9 +149,8 @@ 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
154
- signing_key:
152
+ rubygems_version: 3.3.26
153
+ signing_key:
155
154
  specification_version: 4
156
155
  summary: Configuration and sensible defaults for ElasticSearch on Ruby
157
156
  test_files: