solr_wrapper 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46083a390cb490449cea481a9ea8b3e994d0ad5f
4
- data.tar.gz: be741be5a4f756ed77ea3a689dc7b74daa8fdedc
3
+ metadata.gz: 5211f8f7af81378325cf44e24cb8f93f06662e53
4
+ data.tar.gz: 0251f3cdb0be7e96b17873f50671a73f3bd60214
5
5
  SHA512:
6
- metadata.gz: 278a2fbd55ade0e57220c315a82d7dc403583821e6692393b41edea331e9aafe7d48a8e9847fa76cc87911aa9c41adf79241a5572dea5ac49829b6cca31d5f9f
7
- data.tar.gz: 3de884dae0e77ca16d8eab23a45b6e159282e87ad3a8c4a373e1a5c376abbf68d370f031acce31c39c40e56734e2326ece54ae4c75cc6d1e8565b92ef194b7cc
6
+ metadata.gz: fc74ab3b9c410159b831eebbfbc289ffbd0bd33d83d241c4c8d7ee907cab31f81e869eb7f0cd96db830de8ab6a6cf4944490b22afdfc83218c0b1b26864ecbba
7
+ data.tar.gz: 7c1e5a503b6834218d6621f6a95a4abd744f74b5f68e26846f472cad50ee6276ad588235a91c80209c51ae43bc59d4ba648582f342f13d485a320a48e0845d8d
@@ -2,9 +2,11 @@ module SolrWrapper
2
2
  class Configuration
3
3
  attr_reader :options
4
4
 
5
- def initialize(options)
6
- @options = read_config(options[:config], options[:verbose])
7
- .merge options
5
+ def initialize(options = {})
6
+ @config = options[:config]
7
+ @verbose = options[:verbose]
8
+
9
+ @options = load_configs(Array(options[:config])).merge(options)
8
10
  end
9
11
 
10
12
  def solr_xml
@@ -55,7 +57,7 @@ module SolrWrapper
55
57
  end
56
58
 
57
59
  def default_download_dir
58
- if defined?(Rails) && Rails.root
60
+ if defined?(Rails) && Rails.respond_to?(:root) && Rails.root
59
61
  File.join(Rails.root, 'tmp')
60
62
  else
61
63
  Dir.tmpdir
@@ -87,7 +89,7 @@ module SolrWrapper
87
89
  end
88
90
 
89
91
  def verbose?
90
- !!options.fetch(:verbose, false)
92
+ @verbose || (options && !!options.fetch(:verbose, false))
91
93
  end
92
94
 
93
95
  def version_file
@@ -114,21 +116,23 @@ module SolrWrapper
114
116
  keys.each_with_object({}) { |k, hash| hash[k] = source[k] if source.has_key?(k) }
115
117
  end
116
118
 
117
- def read_config(config_file, verbose)
118
- default_configuration_paths.each do |p|
119
+ def load_configs(config_files)
120
+ config = {}
121
+
122
+ (default_configuration_paths + config_files.compact).each do |p|
119
123
  path = File.expand_path(p)
120
- config_file ||= path if File.exist? path
124
+ next unless File.exist? path
125
+ config.merge!(read_config(path))
121
126
  end
122
127
 
123
- unless config_file
124
- $stdout.puts "No config specified" if verbose
125
- return {}
126
- end
128
+ config
129
+ end
127
130
 
128
- $stdout.puts "Loading configuration from #{config_file}" if verbose
131
+ def read_config(config_file)
132
+ $stdout.puts "Loading configuration from #{config_file}" if verbose?
129
133
  config = YAML.load(ERB.new(IO.read(config_file)).result(binding))
130
134
  unless config
131
- $stderr.puts "Unable to parse config #{config_file}" if verbose
135
+ $stderr.puts "Unable to parse config #{config_file}" if verbose?
132
136
  return {}
133
137
  end
134
138
  convert_keys(config)
@@ -139,7 +143,7 @@ module SolrWrapper
139
143
  end
140
144
 
141
145
  def default_configuration_paths
142
- ['.solr_wrapper', '~/.solr_wrapper']
146
+ ['~/.solr_wrapper.yml', '~/.solr_wrapper', '.solr_wrapper.yml', '.solr_wrapper']
143
147
  end
144
148
  end
145
149
  end
@@ -7,6 +7,8 @@ module SolrWrapper
7
7
  open(url, content_length_proc: ->(bytes) { pbar.total = bytes }, progress_proc: ->(bytes) { pbar.progress = bytes }) do |io|
8
8
  IO.copy_stream(io, output)
9
9
  end
10
+ rescue OpenURI::HTTPError => e
11
+ raise SolrWrapperError, "Unable to download solr from #{url}\n#{e.message}"
10
12
  end
11
13
 
12
14
  class SafeProgressBar < ProgressBar::Base
@@ -123,7 +123,7 @@ module SolrWrapper
123
123
  archive_download_url
124
124
  end
125
125
  end
126
- rescue SocketError, Faraday::Error
126
+ rescue Errno::ECONNRESET, SocketError, Faraday::Error
127
127
  archive_download_url
128
128
  end
129
129
 
@@ -1,3 +1,3 @@
1
1
  module SolrWrapper
2
- VERSION = '0.13.0'
2
+ VERSION = '0.14.0'
3
3
  end
data/lib/solr_wrapper.rb CHANGED
@@ -39,4 +39,6 @@ module SolrWrapper
39
39
  def self.wrap(options = {}, &block)
40
40
  instance(options).wrap &block
41
41
  end
42
+
43
+ class SolrWrapperError < StandardError; end
42
44
  end
@@ -0,0 +1,2 @@
1
+ port: 9998
2
+ verbose: true
@@ -22,13 +22,22 @@ describe SolrWrapper::Configuration do
22
22
  end
23
23
  end
24
24
 
25
- describe "#read_config" do
25
+ describe "#load_configs" do
26
26
  before do
27
27
  allow(config).to receive(:default_configuration_paths).and_return([])
28
28
  end
29
- let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
30
- it "uses values from the config file" do
31
- expect(config.port).to eq '9999'
29
+ context 'with a single config file' do
30
+ let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
31
+ it "uses values from the config file" do
32
+ expect(config.port).to eq '9999'
33
+ end
34
+ end
35
+ context 'with multiple config files' do
36
+ let(:options) { { config: ['spec/fixtures/sample_config.yml', 'spec/fixtures/another_sample_config.yml'] } }
37
+ it "uses values from the config file" do
38
+ expect(config.port).to eq '9998'
39
+ expect(config.verbose?).to eq true
40
+ end
32
41
  end
33
42
  end
34
43
 
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.13.0
4
+ version: 0.14.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: 2016-06-17 00:00:00.000000000 Z
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -167,6 +167,7 @@ files:
167
167
  - lib/solr_wrapper/tasks/solr_wrapper.rake
168
168
  - lib/solr_wrapper/version.rb
169
169
  - solr_wrapper.gemspec
170
+ - spec/fixtures/another_sample_config.yml
170
171
  - spec/fixtures/basic_configs/_rest_managed.json
171
172
  - spec/fixtures/basic_configs/currency.xml
172
173
  - spec/fixtures/basic_configs/lang/stopwords_en.txt
@@ -201,11 +202,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
202
  version: '0'
202
203
  requirements: []
203
204
  rubyforge_project:
204
- rubygems_version: 2.5.1
205
+ rubygems_version: 2.6.4
205
206
  signing_key:
206
207
  specification_version: 4
207
208
  summary: Solr 5 service wrapper
208
209
  test_files:
210
+ - spec/fixtures/another_sample_config.yml
209
211
  - spec/fixtures/basic_configs/_rest_managed.json
210
212
  - spec/fixtures/basic_configs/currency.xml
211
213
  - spec/fixtures/basic_configs/lang/stopwords_en.txt
@@ -220,4 +222,3 @@ test_files:
220
222
  - spec/lib/solr_wrapper/instance_spec.rb
221
223
  - spec/lib/solr_wrapper_spec.rb
222
224
  - spec/spec_helper.rb
223
- has_rdoc: