row_boat 0.2.0 → 0.3.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 +4 -4
- data/API.md +20 -0
- data/gemfiles/csv_import_1.1_and_0.18.gemfile.lock +1 -1
- data/lib/row_boat/base.rb +22 -2
- data/lib/row_boat/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c200c2448e877d0874f0535bf586603d7d86f66c
|
4
|
+
data.tar.gz: 68754e3bb5debe047ba3b48f31a3f3f6849ddbd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
```
|
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
|
271
|
-
merged_options[:wrap_in_transaction]
|
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
|
data/lib/row_boat/version.rb
CHANGED