@@ -29,6 +29,7 @@ def send_notification
29
29
```
30
30
EOS
31
31
32
+ # find all job classes and mailer classes
32
33
definitions = call_helper 'ruby/parse'
33
34
job_classes = definitions . find_classes_by_ancestor ( 'ApplicationJob' ) . map ( &:full_name ) +
34
35
definitions . find_classes_by_ancestor ( 'Sidekiq::Job' ) . map ( &:full_name )
@@ -39,11 +40,14 @@ def send_notification
39
40
callback_names_with_actions = { }
40
41
job_performed_def_names = [ ]
41
42
43
+ # find after_create, after_update, after_save callbacks,
44
+ # and remember InsertAction to insert _commit to the callback name
42
45
find_node node_type : 'call_node' , receiver : nil , name : { in : %i[ after_create after_update after_save ] } do
43
46
callback_names_with_actions [ node . arguments . arguments . first . to_value . to_s ] =
44
47
NodeMutation ::InsertAction . new ( node , '_commit' , to : :name , adapter : mutation_adapter )
45
48
end
46
49
50
+ # find method names that perform a job or deliver a mailer
47
51
find_node node_type : 'def_node' do
48
52
if_exist_node ".call_node[receiver=~/\\ A(#{ job_classes . join ( '|' ) } )/][name IN (perform_later perform_async perform_in perform_at)]" do
49
53
job_performed_def_names << node . name . to_s
@@ -53,6 +57,8 @@ def send_notification
53
57
end
54
58
end
55
59
60
+ # check if the callback method performs a job or deliver a mailer,
61
+ # if so, add the InsertAction
56
62
class_definition = definitions . find_class_by_full_name ( node . full_name )
57
63
callback_names_with_actions . each do |callback_name , action |
58
64
if job_performed_def_names . include? ( callback_name )
0 commit comments