4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/bulletmark_repairer/controller_corrector.rb', line 4
def on_class(node)
node
.children
.each do |child_node|
type, identifier = child_node.to_sexp_array.take(2)
case type
when :def
target_nodes[identifier] = child_node
when :begin
child_node.children.each do |grand_child_node|
type, identifier, callback_type, (_, callback_identifier) = grand_child_node.to_sexp_array
if type == :def
target_nodes[identifier] = grand_child_node
elsif callback_type.in? %i[before_action after_action around_action]
callbacks.append callback_identifier
end
end
end
end
action_node = target_nodes.delete(action)
insert_includes(node: action_node)
return if patched?
callbacks.each { |callback_identifier| insert_includes(node: target_nodes[callback_identifier]) }
end
|