Skip to content

Commit 414674a

Browse files
committed
add local_calls to MethodDefinition
1 parent 836695a commit 414674a

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lib/helpers/parse_ruby.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
end
5757
end
5858

59+
add_callback :call_node, at: 'start' do |node|
60+
if node.receiver.nil? && definitions.current_node_type == "method"
61+
definitions.node.local_calls.push(node.name.to_s)
62+
end
63+
end
64+
5965
add_callback :def_node, at: 'start' do |node|
6066
# we can't handle `def self.inclueded` method
6167
if !node.receiver.nil? && node.name == :included
@@ -324,11 +330,12 @@ def to_h
324330
end
325331

326332
class MethodDefinition
327-
attr_reader :parent, :name
333+
attr_reader :parent, :name, :local_calls
328334

329335
def initialize(parent:, name:)
330336
@parent = parent
331337
@name = name
338+
@local_calls = []
332339
end
333340

334341
def call_method?(method_name)
@@ -341,6 +348,6 @@ def call_any_method?(method_names)
341348
end
342349

343350
def to_h
344-
{ name: @name }
351+
{ name: @name, local_calls: local_calls }
345352
end
346353
end

spec/helpers/parse_ruby_spec.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def bot
2727
end
2828
2929
def self.authenticate?(email, password)
30+
user = find_by(email:)
31+
user.valid_password?(password)
3032
end
3133
3234
def user_type
@@ -59,7 +61,7 @@ def user_type
5961
superclass: "User",
6062
classes: [],
6163
modules: [],
62-
methods: [{ name: "user_type" }],
64+
methods: [{ name: "user_type", local_calls: [] }],
6365
static_methods: [],
6466
constants: [],
6567
included_modules: [],
@@ -72,15 +74,18 @@ def user_type
7274
singleton: {
7375
constants: [],
7476
methods: [
75-
{ name: 'system' },
76-
{ name: 'bot' }
77+
{ name: 'system', local_calls: [] },
78+
{ name: 'bot', local_calls: [] }
7779
],
7880
ancestors: []
7981
},
8082
classes: [],
8183
modules: [],
82-
methods: [{ name: "user_type" }],
83-
static_methods: [{ name: 'authenticate?' }],
84+
methods: [{ name: "user_type", local_calls: [] }],
85+
static_methods: [{
86+
name: 'authenticate?',
87+
local_calls: ['find_by']
88+
}],
8489
constants: [{ name: "ROLES" }],
8590
included_modules: ["Trackable"],
8691
ancestors: ["Trackable"]

0 commit comments

Comments
 (0)