Skip to content

Commit 836695a

Browse files
committed
add MethodDefinition#call_any_method?
1 parent e24a9a3 commit 836695a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/helpers/parse_ruby.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ def call_method?(method_name)
336336
local_calls.any? { |local_call_method_name| parent.find_method_by_name(local_call_method_name)&.call_method?(method_name) }
337337
end
338338

339+
def call_any_method?(method_names)
340+
method_names.any? { |method_name| call_method?(method_name) }
341+
end
342+
339343
def to_h
340344
{ name: @name }
341345
end

spec/helpers/parse_ruby_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,36 @@ def send_notificaiton
205205
expect(method_definition.call_method?('send_notification')).to be_truthy
206206
expect(method_definition.call_method?('activate')).to be_falsey
207207
end
208+
209+
it 'check if call any method' do
210+
rewriter =
211+
Synvert::Rewriter.new 'test', 'ruby_parse_helper' do
212+
call_helper 'ruby/parse'
213+
end
214+
215+
FileUtils.mkdir_p('app/models')
216+
File.write('app/models/user.rb', <<~EOF)
217+
class User < ApplicationRecord
218+
def activate
219+
update(:active: true)
220+
send_notification
221+
end
222+
223+
def deactivate
224+
update(:active: false)
225+
send_notification
226+
end
227+
228+
def send_notificaiton
229+
end
230+
end
231+
EOF
232+
233+
rewriter.process
234+
235+
definitions = rewriter.load_data(:ruby_definitions)
236+
class_definition = definitions.find_class_by_full_name('User')
237+
method_definition = class_definition.find_method_by_name('deactivate')
238+
expect(method_definition.call_any_method?(['send_notification', 'activate'])).to be_truthy
239+
end
208240
end

0 commit comments

Comments
 (0)