Skip to content

Commit 50909ad

Browse files
committed
rename find_class to find_class_by_full_name
1 parent 46d7361 commit 50909ad

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

lib/helpers/parse_ruby.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
class RubyDefinitions
8888
attr_reader :node
8989

90-
delegate :setup_ancestors, :find_classes_by_ancestor, :to_h, to: :@root
90+
delegate :setup_ancestors, :find_class_by_full_name, :find_classes_by_ancestor, :to_h, to: :@root
9191

9292
def initialize
9393
@root = RootDefinition.new
@@ -176,10 +176,10 @@ def setup_ancestors
176176
ancestors = []
177177
superclass = klass.superclass
178178
while superclass
179-
superclass_class = find_class(superclass)
179+
superclass_class = find_class_by_full_name(superclass)
180180
this = self
181181
while !superclass_class && !this.is_a?(RootDefinition)
182-
superclass_class = this.parent.find_class(superclass)
182+
superclass_class = this.parent.find_class_by_full_name(superclass)
183183
this = this.parent
184184
end
185185
if superclass_class
@@ -202,13 +202,13 @@ def setup_ancestors
202202
end
203203
end
204204

205-
def find_class(full_name)
205+
def find_class_by_full_name(full_name)
206206
names = full_name.split('::')
207207
if names.length > 1
208208
mod_name = names.shift
209209
modules.each do |mod|
210210
if mod.name == mod_name
211-
return mod.find_class(names.join('::'))
211+
return mod.find_class_by_full_name(names.join('::'))
212212
end
213213
end
214214
else

spec/helpers/parse_ruby_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ def user_type
9999
})
100100
end
101101

102+
it 'finds classes by full_name' do
103+
rewriter =
104+
Synvert::Rewriter.new 'test', 'ruby_parse_helper' do
105+
call_helper 'ruby/parse'
106+
end
107+
108+
FileUtils.mkdir_p('app/jobs/synvert')
109+
File.write('app/jobs/synvert/user_job.rb', <<~EOF)
110+
module Synvert
111+
class UserJob < SynvertJob
112+
end
113+
end
114+
EOF
115+
116+
rewriter.process
117+
118+
definitions = rewriter.load_data(:ruby_definitions)
119+
class_definition = definitions.find_class_by_full_name('Synvert::UserJob')
120+
expect(class_definition.name).to eq('UserJob')
121+
end
122+
102123
it 'finds classes by superclass' do
103124
rewriter =
104125
Synvert::Rewriter.new 'test', 'ruby_parse_helper' do

0 commit comments

Comments
 (0)