waistband 0.14.3 → 0.15.1

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
- YzA4NjY0MjVjNDZlZjdkZGJlM2Q4NDg2ZDI5YzM4NjQzNWMwMjI3Yw==
4
+ ZGY2N2VmZTYyOTM4MjMzZTk2NTZmNjgyNjRjMjMwODVlMTNkZTAxMQ==
5
5
  data.tar.gz: !binary |-
6
- MDUxOTM4NTNmMGZhNGVlOTEzMDQzMzRjZDJhZGZmYTQ1ODRjYTY0Mg==
6
+ MTRiNmJhMjdkYTliZmU1YWVmMDdhYzk0OTA4N2Q3MmI0NWZiNjk3Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzVlNGU5NzQ4OGZiMjRhNzRkODEwOGQxZmJmYTVkMTE5ZDhmMjEyNjRhNzU4
10
- OWM1OTg0NTg0OWJhYzc0ZjMyMDMyNDlhNTgyMzYzNDM4MGY0NzhjYzU1ZjVm
11
- MjJhODdjMTQ1ZmJmNWMxYjJkMzFiYjk4YmFlNzU0YThmYjkyMjI=
9
+ NjliOGI1ZDhjZTAyMmM1ZGJhNWRjOGI0YTFmZjM0MDQ0YThkOTgxMzMxYjA1
10
+ MzAzMTBhYTQzNzk0MDRjYTA5ZTAxOGVmMjlkOTVlMzk4MDk5YTA1OWQ5YzAx
11
+ YmM4NmRlNzk3ZjM0N2YxYmEzYzBkZjY4NjY4OGQwNmM1YWI2NWM=
12
12
  data.tar.gz: !binary |-
13
- M2U4ZTFhZDFmZGY5YzZhYjc5MjU1NTRhYzE2M2UwZjNlMjNjYTQzNTEwZTE0
14
- MTBjNTdiYTA0YTU4ZWVmMWJmZDNlNTMwODYzYjViMTI1OTUwZTdlNGEyNGRl
15
- NmExODc3YzVkOGYzMWZjM2MyMjk2Nzg4ZTExMjAwYzI2ZWZhZjU=
13
+ MjFjNTllOTExNDYwNzU0MGIwNWI4Yjg1Zjg4ZDZkZjJiZDUzY2I2MWE0NmEz
14
+ MjAzNjM4MWI3MTc2MzVlOTMzOWNmZDQ2ZWI5NGU1NDQwY2NmZjU1MWJjODNl
15
+ MjE4YTFmMDIzMmY2YTliMmRkNzE2MDZhZmFhMTU2MTUxYjgxNmM=
data/Gemfile CHANGED
@@ -3,6 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in waistband.gemspec
4
4
  gemspec
5
5
 
6
- gem 'rspec', '~> 3.0.0'
6
+ gem 'rspec', '~> 3.1.0'
7
7
  gem 'debugger', '~> 1.6.8'
8
8
  gem 'timecop', '~> 0.7.1'
data/lib/waistband.rb CHANGED
@@ -5,6 +5,7 @@ module Waistband
5
5
  autoload :Errors, "waistband/errors"
6
6
  autoload :StringifiedArray, "waistband/stringified_array"
7
7
  autoload :StringifiedHash, "waistband/stringified_hash"
8
+ autoload :Client, "waistband/client"
8
9
  autoload :Configuration, "waistband/configuration"
9
10
  autoload :Index, "waistband/index"
10
11
  autoload :SearchResults, "waistband/search_results"
@@ -0,0 +1,61 @@
1
+ module Waistband
2
+ class Client
3
+
4
+ class << self
5
+
6
+ def from_config(config_hash)
7
+ new(
8
+ config_hash['servers'], randomize_hosts: true,
9
+ retry_on_failure: config_hash['retries'],
10
+ reload_on_failure: config_hash['reload_on_failure'],
11
+ timeout: config_hash['timeout'],
12
+ adapter: config_hash['adapter']
13
+ )
14
+ end
15
+
16
+ end
17
+
18
+ def initialize(servers, options = {})
19
+ @servers = servers
20
+ @randomize_hosts = options.fetch(:randomize_hosts, true)
21
+ @retry_on_failure = options[:retry_on_failure]
22
+ @reload_on_failure = options[:reload_on_failure]
23
+ @timeout = options[:timeout]
24
+ @adapter = options[:adapter]
25
+ end
26
+
27
+ def connection
28
+ @connection ||= Elasticsearch::Client.new config_hash
29
+ end
30
+
31
+ def config_hash
32
+ {
33
+ adapter: @adapter,
34
+ hosts: hosts,
35
+ randomize_hosts: @randomize_hosts,
36
+ retry_on_failure: @retry_on_failure,
37
+ reload_on_failure: @reload_on_failure,
38
+ transport_options: {
39
+ request: {
40
+ open_timeout: @timeout,
41
+ timeout: @timeout
42
+ }
43
+ }
44
+ }
45
+ end
46
+
47
+ def method_missing(method_name, *args, &block)
48
+ return connection.send(method_name, *args, &block) if connection.respond_to?(method_name)
49
+ super
50
+ end
51
+
52
+ private
53
+
54
+ def hosts
55
+ @hosts ||= @servers.map do |server_name, config|
56
+ config
57
+ end
58
+ end
59
+
60
+ end
61
+ end
@@ -40,28 +40,8 @@ module Waistband
40
40
  super
41
41
  end
42
42
 
43
- def hosts
44
- @hosts ||= @yml_config['servers'].map do |server_name, config|
45
- config
46
- end
47
- end
48
-
49
43
  def client
50
- client_hash = {
51
- adapter: @adapter,
52
- hosts: hosts,
53
- randomize_hosts: true,
54
- retry_on_failure: retries,
55
- reload_on_failure: reload_on_failure,
56
- transport_options: {
57
- request: {
58
- open_timeout: timeout,
59
- timeout: timeout
60
- }
61
- }
62
- }
63
-
64
- Elasticsearch::Client.new client_hash
44
+ ::Waistband::Client.from_config(client_config_hash)
65
45
  end
66
46
 
67
47
  def reset_timeout
@@ -70,6 +50,17 @@ module Waistband
70
50
 
71
51
  private
72
52
 
53
+ def client_config_hash
54
+ {
55
+ 'servers' => servers,
56
+ 'randomize_hosts' => true,
57
+ 'retry_on_failure' => retries,
58
+ 'reload_on_failure' => reload_on_failure,
59
+ 'timeout' => timeout,
60
+ 'adapter' => @adapter
61
+ }
62
+ end
63
+
73
64
  def load_yml_with_erb(file)
74
65
  if defined?(ERB)
75
66
  YAML.load(ERB.new(File.read(file)).result)
@@ -196,7 +196,12 @@ module Waistband
196
196
 
197
197
  def client
198
198
  @client ||= begin
199
- _client = ::Waistband.config.client
199
+
200
+ _client = if client_config_hash
201
+ ::Waistband::Client.from_config(client_config_hash)
202
+ else
203
+ ::Waistband.config.client
204
+ end
200
205
 
201
206
  if @log_level && Waistband.config.logger
202
207
  _client.transport.logger = Waistband.config.logger
@@ -204,11 +209,16 @@ module Waistband
204
209
  end
205
210
 
206
211
  _client
212
+
207
213
  end
208
214
  end
209
215
 
210
216
  private
211
217
 
218
+ def client_config_hash
219
+ config['connection']
220
+ end
221
+
212
222
  def get_page_info(body_hash)
213
223
  page = body_hash[:page]
214
224
  page_size = body_hash[:page_size]
@@ -1,3 +1,3 @@
1
1
  module Waistband
2
- VERSION = "0.14.3"
2
+ VERSION = "0.15.1"
3
3
  end
@@ -0,0 +1,22 @@
1
+ development: &DEV
2
+ stringify: true
3
+ connection:
4
+ timeout: 2
5
+ retries: 5
6
+ reload_on_failure: true
7
+ servers:
8
+ server1:
9
+ host: 127.0.0.1
10
+ port: 9200
11
+ protocol: http
12
+ settings:
13
+ index:
14
+ number_of_shards: 1
15
+ number_of_replicas: 1
16
+ mappings:
17
+ event:
18
+ _source:
19
+ includes: ["*"]
20
+
21
+ test:
22
+ <<: *DEV
@@ -19,8 +19,9 @@ describe Waistband::Configuration do
19
19
  end
20
20
 
21
21
  it "proxies the client" do
22
- expect(::Waistband.config.client).to be_a ::Elasticsearch::Transport::Client
23
- expect(::Waistband.client).to be_a ::Elasticsearch::Transport::Client
22
+ expect(::Waistband.config.client).to be_a ::Waistband::Client
23
+ expect(::Waistband.config.client.connection).to be_a ::Elasticsearch::Transport::Client
24
+ expect(::Waistband.client).to be_a ::Waistband::Client
24
25
  end
25
26
 
26
27
  it "permits passing in an adapter to use to the client" do
@@ -42,13 +43,14 @@ describe Waistband::Configuration do
42
43
  expect(::Waistband.config.send(:timeout)).to eql 2
43
44
  end
44
45
 
45
- describe '#hosts' do
46
+ describe 'hosts' do
46
47
 
47
48
  it "returns array of all available servers' configs" do
48
- expect(config.hosts).to be_an Array
49
- expect(config.hosts.size).to eql 2
49
+ hosts = config.client.send(:hosts)
50
+ expect(hosts).to be_an Array
51
+ expect(hosts.size).to eql 2
50
52
 
51
- config.hosts.each_with_index do |server, i|
53
+ hosts.each_with_index do |server, i|
52
54
  expect(server['host']).to match /127\.0\.0\.1|localhost/
53
55
  expect(server['port']).to eql 9200
54
56
  expect(server['protocol']).to eql 'http'
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Waistband::Index do
4
+
5
+ let(:index) { Waistband::Index.new('multi_connection_events') }
6
+ let(:client) { index.client }
7
+
8
+ it "grabs connection data from the index's settings" do
9
+ expect(client).to be_a(::Waistband::Client)
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"}})
12
+ end
13
+
14
+ it "correctly sets hosts" do
15
+ expect(client.send(:config_hash)[:hosts]).to eql([{"host"=>"127.0.0.1", "port"=>9200, "protocol"=>"http"}])
16
+ end
17
+
18
+ it "works" do
19
+ index.delete
20
+ index.create
21
+ index.save('testing123', {ok: 'yeah'})
22
+ index.refresh
23
+ data = index.read('testing123')
24
+ expect(data['_source']['ok']).to eql 'yeah'
25
+ end
26
+
27
+ end
@@ -76,6 +76,13 @@ describe Waistband::Index do
76
76
  expect(result.hits).to be_an Array
77
77
  end
78
78
 
79
+ it "correctly sets hosts" do
80
+ expect(index.client.send(:hosts)).to eql([
81
+ {"host" => "localhost", "port" => 9200, "protocol" => "http"},
82
+ {"host" => "127.0.0.1", "port" => 9200, "protocol" => "http"}
83
+ ])
84
+ end
85
+
79
86
  describe "storing" do
80
87
 
81
88
  it "stores data" do
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: 0.14.3
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Jairala
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-14 00:00:00.000000000 Z
11
+ date: 2014-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -97,6 +97,7 @@ files:
97
97
  - README.md
98
98
  - Rakefile
99
99
  - lib/waistband.rb
100
+ - lib/waistband/client.rb
100
101
  - lib/waistband/configuration.rb
101
102
  - lib/waistband/errors.rb
102
103
  - lib/waistband/index.rb
@@ -109,8 +110,10 @@ files:
109
110
  - spec/config/waistband/waistband_events.yml
110
111
  - spec/config/waistband/waistband_events_no_name.yml
111
112
  - spec/config/waistband/waistband_geo.yml
113
+ - spec/config/waistband/waistband_multi_connection_events.yml
112
114
  - spec/config/waistband/waistband_search.yml
113
115
  - spec/lib/configuration_spec.rb
116
+ - spec/lib/index_multi_connection_spec.rb
114
117
  - spec/lib/index_spec.rb
115
118
  - spec/lib/result_spec.rb
116
119
  - spec/lib/search_results_spec.rb
@@ -146,8 +149,10 @@ test_files:
146
149
  - spec/config/waistband/waistband_events.yml
147
150
  - spec/config/waistband/waistband_events_no_name.yml
148
151
  - spec/config/waistband/waistband_geo.yml
152
+ - spec/config/waistband/waistband_multi_connection_events.yml
149
153
  - spec/config/waistband/waistband_search.yml
150
154
  - spec/lib/configuration_spec.rb
155
+ - spec/lib/index_multi_connection_spec.rb
151
156
  - spec/lib/index_spec.rb
152
157
  - spec/lib/result_spec.rb
153
158
  - spec/lib/search_results_spec.rb