row_boat 0.3.0 → 0.4.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: c200c2448e877d0874f0535bf586603d7d86f66c
4
- data.tar.gz: 68754e3bb5debe047ba3b48f31a3f3f6849ddbd7
3
+ metadata.gz: 3b62eece81abe5efcd17486c08f0e2ba6b654bd9
4
+ data.tar.gz: 6d3958463a1c159b07dc00ac3a820334b8189094
5
5
  SHA512:
6
- metadata.gz: 35dda1c8b70719bb5f047fd7e9f3cd6824328096c7018ceae05e09e9790c99d8b8ad18fd7a9aa069a0df84c615a6bc00b29a24e824035f81cfa0c6d9f73cdbd2
7
- data.tar.gz: 8111ee6feb86822b686a2b896ed5fc29e82563107ebe2fb80e85fe1df4dd2f3712ff8111262b395c9ac9596c59f8981b702e6b5c7e4969479ab038a35949ac38
6
+ metadata.gz: de9025837e9acad6c5ae29b838db3a48583a6f258b74e48833788ff6186046d678959513e7e98214b09b723b4d079940f3eec880e7a8cbe36de4323bcf4fd64d
7
+ data.tar.gz: 2fb52393859c0e1ec2ce272a6a888fbdaf032afc5a64ab1a2ea93946b3a8176d47e6a238b63a34cdd7435ee2aad5f03a6ca80e8b1aaef444c1529ef493418b50
data/API.md CHANGED
@@ -48,6 +48,7 @@ It returns a hash containing
48
48
  - `:invalid_records` - an array of all records that failed to import since they were invalid. If you've configured the `:validate` option to be `false` it will be an empty array.
49
49
  - `:total_inserted` - the total number of records inserted into the database.
50
50
  - `:inserted_ids` - an array of all of the ids of records inserted into the database.
51
+ - `:skipped_rows` - every row skipped by returning `nil` from [`preprocess_row`](#preprocess_row).
51
52
 
52
53
  If you want to pass additional information to help import CSVs, *don't override this method*. It just passes through to [`initialize`](#initialize) so override that :)
53
54
 
@@ -195,7 +196,7 @@ end
195
196
 
196
197
  Implement this method if you need to do some work on the row before the record is inserted/updated.
197
198
 
198
- If you return `nil` from this method, the row will be skipped in the import.
199
+ If you return `nil` from this method, the row will be skipped in the import. You can access these rows in the return value from [`.import`](#import) (the `:skipped_rows` key).
199
200
 
200
201
  You also have access to `row_number` here.
201
202
 
data/README.md CHANGED
@@ -23,17 +23,13 @@ It uses [SmarterCSV](https://github.com/tilo/smarter_csv) and [`activerecord-imp
23
23
  Add this line to your application's Gemfile:
24
24
 
25
25
  ```ruby
26
- gem "row_boat", "~> 0.1"
26
+ gem "row_boat", "~> 0.4"
27
27
  ```
28
28
 
29
29
  And then execute:
30
30
 
31
31
  $ bundle
32
32
 
33
- Or install it yourself as:
34
-
35
- $ gem install row_boat
36
-
37
33
  ## Basic Usage
38
34
 
39
35
  #### [Full documentation can be found here.](/API.md#rowboat-api)
@@ -41,7 +37,7 @@ Or install it yourself as:
41
37
  Below we're defining the required methods ([`import_into`](/API.md#import_into) and [`column_mapping`](/API.md#column_mapping)) and a few additional options as well (via [`value_converters`](/API.md#value_converters) and [`options`](/API.md#options)). Checkout [API.md](/API.md#rowboat-api) for the full documentation for more details :)
42
38
 
43
39
  ```ruby
44
- class ImportProduct
40
+ class ImportProduct < RowBoat::Base
45
41
  # required
46
42
  def import_into
47
43
  Product # The ActiveRecord class we want to import records into.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- row_boat (0.3.0)
4
+ row_boat (0.4.0)
5
5
  activerecord (>= 5.0.0)
6
6
  activerecord-import (~> 0.18.2)
7
7
  smarter_csv (~> 1.1)
data/lib/row_boat/base.rb CHANGED
@@ -16,7 +16,7 @@ module RowBoat
16
16
  # @overload import(csv_source)
17
17
  # @param csv_source [String, #read] a CSV-like object that SmarterCSV can read.
18
18
  #
19
- # @return [Hash] a hash with +:invalid_records+, +:total_inserted+ and +:inserted_ids+.
19
+ # @return [Hash] a hash with +:invalid_records+, +:total_inserted+, +:inserted_ids+, and +:skipped_rows+.
20
20
  #
21
21
  # @see https://github.com/tilo/smarter_csv#documentation SmarterCSV Docs
22
22
  def import(*args, &block)
@@ -40,7 +40,7 @@ module RowBoat
40
40
  # Parses the csv and inserts/updates the database. You probably won't call this method directly,
41
41
  # instead you would call {RowBoat::Base.import}.
42
42
  #
43
- # @return [Hash] a hash with +:invalid_records+, +:total_inserted+ and +:inserted_ids+.
43
+ # @return [Hash] a hash with +:invalid_records+, +:total_inserted+, +:inserted_ids+, and +:skipped_rows+.
44
44
  def import
45
45
  import_results = []
46
46
 
@@ -124,7 +124,7 @@ module RowBoat
124
124
  rows.each_with_object([]) do |row, preprocessed_rows|
125
125
  increment_row_number
126
126
  preprocessed_row = preprocess_row(row)
127
- preprocessed_rows << preprocessed_row unless preprocessed_row.nil?
127
+ preprocessed_row ? preprocessed_rows << preprocessed_row : add_skipped_row(row)
128
128
  end
129
129
  end
130
130
 
@@ -246,12 +246,21 @@ module RowBoat
246
246
  # @private
247
247
  attr_reader :row_number
248
248
 
249
+ # @api private
250
+ # @private
251
+ attr_reader :skipped_rows
252
+
249
253
  # @api private
250
254
  # @private
251
255
  def increment_row_number
252
256
  @row_number = row_number.to_i + 1
253
257
  end
254
258
 
259
+ def add_skipped_row(row)
260
+ @skipped_rows ||= []
261
+ skipped_rows << row
262
+ end
263
+
255
264
  # @api private
256
265
  # @private
257
266
  def column_mapping_options
@@ -297,7 +306,8 @@ module RowBoat
297
306
  import_results.each_with_object(
298
307
  invalid_records: [],
299
308
  total_inserted: 0,
300
- inserted_ids: []
309
+ inserted_ids: [],
310
+ skipped_rows: skipped_rows
301
311
  ) do |import_result, total_results|
302
312
  total_results[:invalid_records] += import_result.failed_instances
303
313
  total_results[:total_inserted] += import_result.num_inserts
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RowBoat
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: row_boat
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
  - Michael Crismali
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-17 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord