traject_sequel_writer 0.11.0 → 0.12.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: 81efee56a46a47e26c17eff759d4cc0a7dc36726
4
- data.tar.gz: 72a8923c02d9e6052342c4c953fbc9cc34857ca2
3
+ metadata.gz: e73f97cb0e4558e71b2960c0d42accad74041758
4
+ data.tar.gz: 1e0e5f6ddacfef11a408e503ee987a7dc8f0ba35
5
5
  SHA512:
6
- metadata.gz: 7e5a7a0710a5e8fa437bf4a8976119ef8f4a8a8995a7eb4633364eb17ef666e6472d44f5bef965c434d208ed9c3cd101638276f74572164bd53c3c03ae1629c3
7
- data.tar.gz: ba50260b19700091db4d1827bcf80446595b40a7b53933312028c4524da1143af425c65f7a6bd481fb41b7322bb87355661effbc7cf25c1ddf2b691ed75cb616
6
+ metadata.gz: cdc2945a7cd9457e4a287e00948bd069bc6c9b081aac8686addb3ebeef6d8076ddf2bbb9b717385c575b0098f092f6c87735545abdd25b2b2c6cd9c33d37dc0f
7
+ data.tar.gz: 0ef683cf6ee481e62ad600d088919fd537817459793d49d3645e954291e546a95145dc32133e377bd50cfa52e0b2e15595aa24d18228d354005b50224b5fce82
data/README.md CHANGED
@@ -9,6 +9,7 @@ The writer can be used as standard, as the destination of your indexing pipeline
9
9
 
10
10
  It was actually written for a use case where it's used as a "side effect" in a traject `each_record`, writing different data out to an rdbms on the side, while the main indexing is to Solr. This ends up a bit hacky at present but works.
11
11
 
12
+ Currently has a pre-1.0 release number, as it has not seen wide use, and may have some oddities.
12
13
 
13
14
  ## Installation
14
15
 
@@ -140,11 +140,33 @@ module Traject
140
140
 
141
141
  def hash_to_array(column_names, hash)
142
142
  column_names.collect do |c|
143
- v = hash[c.to_s]
144
- v.kind_of?(Array) ? v.join(@internal_delimiter) : v
143
+ output_value_to_column_value(hash[c.to_s])
145
144
  end
146
145
  end
147
146
 
147
+ # Traject context.output_hash values are arrays.
148
+ # turn them into good column values, joining strings if needed.
149
+ #
150
+ # Single values also accepted, even though not traject standard, they
151
+ # will be passed through unchanged.
152
+ def output_value_to_column_value(v)
153
+ if v.kind_of?(Array)
154
+ if v.length == 0
155
+ nil
156
+ elsif v.length == 1
157
+ v.first
158
+ elsif v.first.kind_of?(String)
159
+ v.join(@internal_delimiter)
160
+ else
161
+ # Not a string? Um, raise for now?
162
+ raise ArgumentError.new("Traject::SequelWriter, multiple non-String values provided: #{v}")
163
+ end
164
+ else
165
+ v
166
+ end
167
+ end
168
+
169
+
148
170
  def after_send_batch(&block)
149
171
  @after_send_batch_callbacks << block
150
172
  end
@@ -1,3 +1,3 @@
1
1
  module TrajectSequelWriter
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.0"
3
3
  end
@@ -1,10 +1,9 @@
1
+ require 'minitest'
1
2
  require 'minitest/autorun'
2
3
  require 'minitest/spec'
3
4
 
4
5
  require 'traject_sequel_writer'
5
6
 
6
- require 'minitest/autorun'
7
-
8
7
  require 'sequel'
9
8
 
10
9
  # Create a temporary sqlite db for tests, remove it when we're done
@@ -41,6 +41,19 @@ describe "Traject::SequelWriter" do
41
41
  assert @writer.db_table.where(:string_a => "String_One,String_Two", :string_b => "String_B_One").count == 1, "Expected written row with expected values"
42
42
  end
43
43
 
44
+ it "complains about multiple non-string values" do
45
+ @writer = self.writer
46
+
47
+ context = Traject::Indexer::Context.new
48
+ context.output_hash.merge!(
49
+ "int_a" => [1001, 1002]
50
+ )
51
+ assert_raises(ArgumentError) do
52
+ @writer.put context
53
+ @writer.close
54
+ end
55
+ end
56
+
44
57
  after do
45
58
  @writer.db_table.delete
46
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traject_sequel_writer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind