solr_wrapper 0.13.2 → 0.14.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: 144bd1cb3f82253c8f8087f4eacf2d28eead0dc2
4
- data.tar.gz: 12c08521281d856eea0bdb2bcc0facda073313b1
3
+ metadata.gz: 5211f8f7af81378325cf44e24cb8f93f06662e53
4
+ data.tar.gz: 0251f3cdb0be7e96b17873f50671a73f3bd60214
5
5
  SHA512:
6
- metadata.gz: f8f0b4e93e6a5f5c5dcbc3fee67ce1875d3c5a36fd0c4dea4c9fa80f3c1c39ebcebb920c24ad31b3c5ea471b139b9dabf81bba4195aada4098e4c3d45e0d2eaa
7
- data.tar.gz: e2eb48930e2e95ad2f3e1d045ccf6490dcd0f13c800161b316daffd2e02f656e9a33326f47ab47b8d871ded04ea1772340db9690201ca00e45f0a1fbfe4606cf
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module SolrWrapper
2
- VERSION = '0.13.2'
2
+ VERSION = '0.14.0'
3
3
  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.2
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-07-05 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
@@ -206,6 +207,7 @@ 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