solr_wrapper 0.3.0 → 0.4.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
2
  SHA1:
3
- metadata.gz: 02801c03fb674022382afba55cb728b5ec82d177
4
- data.tar.gz: e042c59c01ab0ed69f48a0415032c5e5f798ae4b
3
+ metadata.gz: ce8d8ac85d7a99148fca4876c7b9e5ce092224f7
4
+ data.tar.gz: 7dc6333a599a500d996d50e03d777b86429a00e8
5
5
  SHA512:
6
- metadata.gz: 36168cce73a5fef10a0e683068363955f94f23cfc92132f6bf856b89d75605f9a804506aa8d2cd6bdc07acdc930f5053fb43a6aab7eeac311eb9d427b9f04d06
7
- data.tar.gz: c9e006036531e1e31a23b3babda62345a1c6742d741d7ede1fa4f2eeac579f3dd3372dacfc9f6be6924dfdee883bc594b9b1f39882fe17f52db90f077cd16466
6
+ metadata.gz: ee2b2a29b6dd15c5b0e02fa11f6bef560394437b5bb3c69639e00d9ac35de9cb953f76e298b8b67f27d3209238a1fb60929293f506fdc33dd4b9d43a03c2a0f2
7
+ data.tar.gz: 9ad3a192f2bf3d68ee18b4213154ec975dd7107b705e0d4e5b34827a03e02535b727725887948d495d781d900ddf4d33956d3f3fc6fe4d14a57d7296281fae06
@@ -4,6 +4,7 @@ require 'json'
4
4
  require 'open-uri'
5
5
  require 'ruby-progressbar'
6
6
  require 'securerandom'
7
+ require 'socket'
7
8
  require 'stringio'
8
9
  require 'tmpdir'
9
10
  require 'zip'
@@ -133,10 +134,16 @@ module SolrWrapper
133
134
  end
134
135
  end
135
136
 
137
+ ##
138
+ # Get the host this Solr instance is bound to
139
+ def host
140
+ '127.0.0.1'
141
+ end
142
+
136
143
  ##
137
144
  # Get the port this Solr instance is running at
138
145
  def port
139
- options.fetch(:port, "8983").to_s
146
+ @port ||= options.fetch(:port, random_open_port).to_s
140
147
  end
141
148
 
142
149
  ##
@@ -159,7 +166,7 @@ module SolrWrapper
159
166
  ##
160
167
  # Get a (likely) URL to the solr instance
161
168
  def url
162
- "http://127.0.0.1:#{port}/solr/"
169
+ "http://#{host}:#{port}/solr/"
163
170
  end
164
171
 
165
172
  def configure
@@ -329,7 +336,7 @@ module SolrWrapper
329
336
  end
330
337
 
331
338
  def version
332
- @version ||= options.fetch(:version, default_solr_version)
339
+ @version ||= options.fetch(:version, SolrWrapper.default_solr_version)
333
340
  end
334
341
 
335
342
  def solr_options
@@ -340,10 +347,6 @@ module SolrWrapper
340
347
  options.fetch(:env, {})
341
348
  end
342
349
 
343
- def default_solr_version
344
- SolrWrapper.default_solr_version
345
- end
346
-
347
350
  def download_path
348
351
  @download_path ||= options.fetch(:download_path, default_download_path)
349
352
  end
@@ -418,6 +421,16 @@ module SolrWrapper
418
421
  end
419
422
  end
420
423
 
424
+ def random_open_port
425
+ socket = Socket.new(:INET, :STREAM, 0)
426
+ begin
427
+ socket.bind(Addrinfo.tcp('127.0.0.1', 0))
428
+ socket.local_address.ip_port
429
+ ensure
430
+ socket.close
431
+ end
432
+ end
433
+
421
434
  def raise_error_unless_extracted
422
435
  raise RuntimeError, "there is no solr instance at #{instance_dir}. Run SolrWrapper.extract first." unless extracted?
423
436
  end
@@ -1,3 +1,3 @@
1
1
  module SolrWrapper
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/solr_wrapper.rb CHANGED
@@ -7,7 +7,14 @@ module SolrWrapper
7
7
  end
8
8
 
9
9
  def self.default_instance_options
10
- @default_instance_options ||= {}
10
+ @default_instance_options ||= {
11
+ port: '8983',
12
+ version: SolrWrapper.default_solr_version
13
+ }
14
+ end
15
+
16
+ def self.default_instance_options=(options)
17
+ @default_instance_options = options
11
18
  end
12
19
 
13
20
  def self.default_instance(options = {})
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe SolrWrapper::Instance do
4
4
  let(:solr_instance) { SolrWrapper::Instance.new }
5
5
  subject { solr_instance }
6
- let(:client) { SimpleSolrClient::Client.new("http://localhost:#{subject.port}/solr/") }
6
+ let(:client) { SimpleSolrClient::Client.new(subject.url) }
7
7
  describe "#with_collection" do
8
8
  it "should create a new anonymous collection" do
9
9
  subject.wrap do |solr|
@@ -12,4 +12,11 @@ describe SolrWrapper do
12
12
  end
13
13
  end
14
14
  end
15
+
16
+ describe ".default_instance_options=" do
17
+ it "sets default options" do
18
+ SolrWrapper.default_instance_options = { port: '1234' }
19
+ expect(SolrWrapper.default_instance_options[:port]). to eq '1234'
20
+ end
21
+ end
15
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solr_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-15 00:00:00.000000000 Z
11
+ date: 2015-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip