waistband 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTJiYTBiZGZiN2FmYWEzZTdlZGFhYmU5NjA3MjAyMDgwZTM2MmVhZQ==
4
+ ZDE2ZWE0ODU1NDM1YzMzM2UwOGIxMDlhZDRhODUxZWI5NDIxMDc3Mw==
5
5
  data.tar.gz: !binary |-
6
- N2I2MDAzZTEwNGViZGQ0NDE5MWY1NzAyOGE4YTVmMmEwNzk0YTVjYw==
6
+ NGE4YjJhNjc2NDNhMjQ1Zjc3MDU5ZTE4MjZhNTY2ZWIxYjFjZGJiNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTU3ZWVjMGMzNDc2NWQzYTRhYmRjYmE3ODgzODk3ZDkzZDk0ZWQ5ZTczNmMx
10
- MjA3M2ZlOTU1NGQ4NTI0OTVlZTc1ZDg0MTEyYTlkMjBlMDE3ODgyOGE4YmUw
11
- ZjU4OTUyY2Q3YTJmY2RjNmFhZTFhM2ZlMzNkNTkzODUyZDg1OGM=
9
+ MTA4NzM4Zjk5YTk0NjZmOGE3OTk4OGUyZGQzYTMyZDkxODFlZGFhNzM2ZDM1
10
+ NzU0NWU4ZGJiNDk2YzA0ZWM2Zjc1MDJkNzcyYjcxZDRlYTQzNzQ0ZWIxMTYy
11
+ Y2U4NDA5NDVkMTJhYmU0MTkxMzhmOGUyZjA4YjM4ZmI5MGI4MjI=
12
12
  data.tar.gz: !binary |-
13
- NGMwMjdiZDUwYzE4ZjQxM2RlZjA5YzZlNzQxNWZlYWJkYzRhN2RmYzM4ZTlh
14
- YjRkYTJiYmQ5Njg1ZmMyM2I5ODkxOWVlNWViMzliY2Y2YjVlZWQ0OTgwZTQ1
15
- ZWVjYzA0NjlkZjFkODZiNDA0YTRhMmJlNDk1NzVlMDY5MTdkNjQ=
13
+ NGMwMzA4MGIxZjAyNmIyMzMyMWQxMzllZTM3YzJlZTM3YjI4MDBjOTU2MjRl
14
+ ZmZjZDlmZDJkZjhiOGMzNThlZDAwNDhhN2QxN2JlNDY1MzNjNzIwYmEwM2E0
15
+ MDk5NTc0MWVkNzZkOGE2YzE2MGI1NDcyZjIwODU1OTcwMjE3ZGY=
@@ -10,7 +10,7 @@ module Waistband
10
10
 
11
11
  attr_accessor :config_dir
12
12
  attr_writer :timeout
13
- attr_reader :env
13
+ attr_reader :env, :logger
14
14
 
15
15
  def initialize
16
16
  @yml_config = {}
@@ -68,6 +68,10 @@ module Waistband
68
68
  remove_instance_variable '@timeout'
69
69
  end
70
70
 
71
+ def logger=(logger)
72
+ @logger = logger
73
+ end
74
+
71
75
  private
72
76
 
73
77
  def load_yml_with_erb(file)
@@ -12,7 +12,8 @@ module Waistband
12
12
  options = options.stringify_keys
13
13
 
14
14
  @index_name = index_name
15
- @stringify = config['stringify']
15
+ @stringify = config['stringify']
16
+ @log_level = config['log_level']
16
17
 
17
18
  # subindexes checks
18
19
  if options['version'].present?
@@ -67,7 +68,7 @@ module Waistband
67
68
  end
68
69
 
69
70
  def create!
70
- client.indices.create index: config_name, body: config.except('name', 'stringify')
71
+ client.indices.create index: config_name, body: config.except('name', 'stringify', 'log_level')
71
72
  rescue Elasticsearch::Transport::Transport::Errors::BadRequest => ex
72
73
  raise ex unless ex.message.to_s =~ /IndexAlreadyExistsException/
73
74
  raise ::Waistband::Errors::IndexExists.new("Index already exists")
@@ -194,7 +195,16 @@ module Waistband
194
195
  end
195
196
 
196
197
  def client
197
- @client ||= ::Waistband.config.client
198
+ @client ||= begin
199
+ _client = ::Waistband.config.client
200
+
201
+ if @log_level && Waistband.config.logger
202
+ _client.transport.logger = Waistband.config.logger
203
+ _client.transport.logger.level = @log_level
204
+ end
205
+
206
+ _client
207
+ end
198
208
  end
199
209
 
200
210
  private
@@ -1,3 +1,3 @@
1
1
  module Waistband
2
- VERSION = "0.13.0"
2
+ VERSION = "0.14.0"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  development: &DEV
2
2
  stringify: false
3
+ log_level: 2 # warning
3
4
  settings:
4
5
  index:
5
6
  number_of_shards: 1
@@ -323,4 +323,34 @@ describe Waistband::Index do
323
323
 
324
324
  end
325
325
 
326
+ describe 'logging' do
327
+
328
+ class FakeLog
329
+ attr_reader :level
330
+
331
+ def level=(val)
332
+ @level = val
333
+ end
334
+
335
+ def info(val); end
336
+ def debug(val); end
337
+ def fatal(val); end
338
+ end
339
+
340
+ before do
341
+ Waistband.config.logger = FakeLog.new
342
+ end
343
+
344
+ it "sets the index's client transport logger" do
345
+ expect(index2.client.transport.logger).to be_a FakeLog
346
+ expect(index2.client.transport.logger.level).to eql 2
347
+ end
348
+
349
+ it "logs" do
350
+ expect(Waistband.config.logger).to receive(:info).with(kind_of(String)).once
351
+ index2.search({})
352
+ end
353
+
354
+ end
355
+
326
356
  end
data/spec/spec_helper.rb CHANGED
@@ -21,6 +21,7 @@ RSpec.configure do |config|
21
21
  end
22
22
 
23
23
  config.around(:each) do |example|
24
+ IndexHelper.delete_all
24
25
  IndexHelper.create_all
25
26
  example.run
26
27
  IndexHelper.delete_all
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waistband
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Jairala