mirror of
https://github.com/ruby/ruby.git
synced 2025-08-16 05:59:00 +02:00

(https://github.com/ruby/rdoc/pull/1114)
It's hard to distinguish code object classes by their file names alone.
And given that we have 18 such classes, it'd make the codebase a lot
easier to understand if we grouped them into a single directory.
Given that these classes are all autoloaded in `lib/rdoc.rb` instead
of required individually, this change should have minimum impact on
projects using RDoc as they generally just require `rdoc`, not individual
files. An example is Rails' `sdoc`:
https://github.com/rails/sdoc/blob/main/lib/sdoc/rdoc_monkey_patches.rb
4211292ffe
51 lines
964 B
Ruby
51 lines
964 B
Ruby
# frozen_string_literal: true
|
|
##
|
|
# A file loaded by \#require
|
|
|
|
class RDoc::Require < RDoc::CodeObject
|
|
|
|
##
|
|
# Name of the required file
|
|
|
|
attr_accessor :name
|
|
|
|
##
|
|
# Creates a new Require that loads +name+ with +comment+
|
|
|
|
def initialize(name, comment)
|
|
super()
|
|
@name = name.gsub(/'|"/, "") #'
|
|
@top_level = nil
|
|
self.comment = comment
|
|
end
|
|
|
|
def inspect # :nodoc:
|
|
"#<%s:0x%x require '%s' in %s>" % [
|
|
self.class,
|
|
object_id,
|
|
@name,
|
|
parent_file_name,
|
|
]
|
|
end
|
|
|
|
def to_s # :nodoc:
|
|
"require #{name} in: #{parent}"
|
|
end
|
|
|
|
##
|
|
# The RDoc::TopLevel corresponding to this require, or +nil+ if not found.
|
|
|
|
def top_level
|
|
@top_level ||= begin
|
|
tl = RDoc::TopLevel.all_files_hash[name + '.rb']
|
|
|
|
if tl.nil? and RDoc::TopLevel.all_files.first.full_name =~ %r(^lib/) then
|
|
# second chance
|
|
tl = RDoc::TopLevel.all_files_hash['lib/' + name + '.rb']
|
|
end
|
|
|
|
tl
|
|
end
|
|
end
|
|
|
|
end
|