data_shifter 0.1.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.
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module DataShifter
6
- # In data shift files, `transaction false` disables automatic transaction
7
- # and rollback. DB writes (and side effects) are not rolled back on dry run, so
8
- # the shift must guard them with `return if dry_run?` or `return unless dry_run?`.
9
- #
10
- # @example
11
- # # bad
12
- # class BackfillUsers < DataShifter::Shift
13
- # transaction false
14
- # def process_record(record)
15
- # record.update!(foo: 1)
16
- # end
17
- # end
18
- #
19
- # # good
20
- # class BackfillUsers < DataShifter::Shift
21
- # transaction false
22
- # def process_record(record)
23
- # return if dry_run?
24
- # record.update!(foo: 1)
25
- # end
26
- # end
27
- class SkipTransactionGuardDryRun < Base
28
- MSG = "Data shifts using `transaction false` must guard writes/side effects with " \
29
- "`return if dry_run?` or `return unless dry_run?`."
30
-
31
- def_node_matcher :skip_transaction_call?, <<~PATTERN
32
- (send _ :transaction {(sym :none) (false)})
33
- PATTERN
34
-
35
- def on_send(node)
36
- return unless skip_transaction_call?(node)
37
- return if file_contains_dry_run_guard?
38
-
39
- add_offense(node, message: MSG)
40
- end
41
-
42
- private
43
-
44
- def file_contains_dry_run_guard?
45
- return true unless processed_source.ast
46
-
47
- processed_source.ast.each_node(:send) do |send_node|
48
- return true if send_node.method?(:dry_run?)
49
- end
50
- false
51
- end
52
- end
53
- end
54
- end
55
- end