row_boat 0.2.0 → 0.3.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: 349a16106d1b36fe5758231d5f7569573892293f
4
- data.tar.gz: 02a54356f10fbd87fc23b618301cc597e7028ded
3
+ metadata.gz: c200c2448e877d0874f0535bf586603d7d86f66c
4
+ data.tar.gz: 68754e3bb5debe047ba3b48f31a3f3f6849ddbd7
5
5
  SHA512:
6
- metadata.gz: fbbb578399fdafbbb597af6658d2d09935e9599805bfcccb640df24344e0c4db0a2c94c0b35d3afdef7aaa02948933e17d299fa017f375a22133245b99970eae
7
- data.tar.gz: be36d03d5051fd7e1810da7be25f368cab0ee1c7a285f4bfc6907db746297c38785d3e8b4306f6aadf3f9cffc600816b15cb3a06e3cd9b5e11bf42a71b8f504a
6
+ metadata.gz: 35dda1c8b70719bb5f047fd7e9f3cd6824328096c7018ceae05e09e9790c99d8b8ad18fd7a9aa069a0df84c615a6bc00b29a24e824035f81cfa0c6d9f73cdbd2
7
+ data.tar.gz: 8111ee6feb86822b686a2b896ed5fc29e82563107ebe2fb80e85fe1df4dd2f3712ff8111262b395c9ac9596c59f8981b702e6b5c7e4969479ab038a35949ac38
data/API.md CHANGED
@@ -17,6 +17,7 @@ This is really more of a summary of what you can do with `RowBoat::Base` since y
17
17
  - [`handle_failed_row`](#handle_failed_row)
18
18
  - [`handle_failed_rows`](#handle_failed_rows)
19
19
  - [`value_converters`](#value_converters)
20
+ - [`rollback_transaction?`](#rollback_transaction)
20
21
 
21
22
  ## Basic Usage
22
23
 
@@ -364,3 +365,22 @@ module DescriptionConverter
364
365
  end
365
366
  end
366
367
  ```
368
+
369
+ ## `rollback_transaction?`
370
+
371
+ ### Description
372
+
373
+ Implement this method if you'd like to rollback the transaction after it otherwise has completed.
374
+
375
+ Note: imports are only wrapped in a transaction if the `wrap_in_transaction` option is `true`. It defaults to `true` but this can be configured in [`options`](#options)
376
+
377
+ ### Example
378
+
379
+ ```ruby
380
+ class ImportProduct < RowBoat::Base
381
+ # required configuration omitted for brevity
382
+ def rollback_transaction?
383
+ CsvService.already_imported?(csv_source)
384
+ end
385
+ end
386
+ ```
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- row_boat (0.2.0)
4
+ row_boat (0.3.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
@@ -228,6 +228,19 @@ module RowBoat
228
228
  end
229
229
  end
230
230
 
231
+ # Implement this method if you'd like to rollback the transaction
232
+ # after it otherwise has completed.
233
+ #
234
+ # @abstract
235
+ #
236
+ # @note Only works if the `wrap_in_transaction` option is `true`
237
+ # (which is the default)
238
+ #
239
+ # @return [Boolean]
240
+ def rollback_transaction?
241
+ false
242
+ end
243
+
231
244
  private
232
245
 
233
246
  # @private
@@ -267,8 +280,15 @@ module RowBoat
267
280
 
268
281
  # @api private
269
282
  # @private
270
- def transaction_if_needed(&block)
271
- merged_options[:wrap_in_transaction] ? import_into.transaction(&block) : yield
283
+ def transaction_if_needed
284
+ if merged_options[:wrap_in_transaction]
285
+ import_into.transaction do
286
+ yield
287
+ raise ActiveRecord::Rollback if rollback_transaction?
288
+ end
289
+ else
290
+ yield
291
+ end
272
292
  end
273
293
 
274
294
  # @api private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RowBoat
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: row_boat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Crismali