Skip to content

Commit ef26ab6

Browse files
committed
Rename top_level method to file_context
1 parent d6c5cf5 commit ef26ab6

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

lib/rdoc/code_object/context.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def add_class(class_type, given_name, superclass = '::Object')
297297
# find the name & enclosing context
298298
if given_name =~ /^:+(\w+)$/ then
299299
full_name = $1
300-
enclosing = top_level
300+
enclosing = file_context
301301
name = full_name.split(/:+/).last
302302
else
303303
full_name = child_name given_name
@@ -1189,18 +1189,20 @@ def to_s # :nodoc:
11891189
end
11901190

11911191
##
1192-
# Return the TopLevel that owns us
1192+
# Return the File that owns us
11931193
#--
1194-
# FIXME we can be 'owned' by several TopLevel (see #record_location &
1194+
# FIXME we can be 'owned' by several Files (see #record_location &
11951195
# #in_files)
11961196

1197-
def top_level
1198-
return @top_level if defined? @top_level
1199-
@top_level = self
1200-
@top_level = @top_level.parent until RDoc::File === @top_level
1201-
@top_level
1197+
def file_context
1198+
return @file_context if defined? @file_context
1199+
@file_context = self
1200+
@file_context = @file_context.parent until @file_context.nil? or RDoc::File === @file_context
1201+
@file_context
12021202
end
12031203

1204+
alias_method :top_level, :file_context # :nodoc:
1205+
12041206
##
12051207
# Upgrades NormalModule +mod+ in +enclosing+ to a +class_type+
12061208

lib/rdoc/code_object/require.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class RDoc::Require < RDoc::CodeObject
1515
def initialize(name, comment)
1616
super()
1717
@name = name.gsub(/'|"/, "") #'
18-
@top_level = nil
18+
@file_context = nil
1919
self.comment = comment
2020
end
2121

@@ -35,17 +35,19 @@ def to_s # :nodoc:
3535
##
3636
# The RDoc::File corresponding to this require, or +nil+ if not found.
3737

38-
def top_level
39-
@top_level ||= begin
40-
tl = RDoc::File.all_files_hash[name + '.rb']
38+
def file_context
39+
@file_context ||= begin
40+
f = RDoc::File.all_files_hash[name + '.rb']
4141

42-
if tl.nil? and RDoc::File.all_files.first.full_name =~ %r(^lib/) then
42+
if f.nil? and RDoc::File.all_files.first.full_name =~ %r(^lib/) then
4343
# second chance
44-
tl = RDoc::File.all_files_hash['lib/' + name + '.rb']
44+
f = RDoc::File.all_files_hash['lib/' + name + '.rb']
4545
end
4646

47-
tl
47+
f
4848
end
4949
end
5050

51+
alias_method :top_level, :file_context # :nodoc:
52+
5153
end

lib/rdoc/parser/c.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ def handle_class_module(var_name, type, class_name, parent, in_module)
897897
cm = enclosure.add_module RDoc::NormalModule, class_name
898898
end
899899

900-
cm.record_location enclosure.top_level
900+
cm.record_location enclosure.file_context
901901

902902
find_class_comment cm.full_name, cm
903903

test/rdoc/rdoc_context_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def test_add_require
320320
@c1.add_require req
321321

322322
assert_empty @c1.requires
323-
assert_includes @c1.top_level.requires, req
323+
assert_includes @c1.file_context.requires, req
324324
end
325325

326326
def test_add_section

0 commit comments

Comments
 (0)