require.rb 935 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ##
  2. # A file loaded by \#require
  3. class RDoc::Require < RDoc::CodeObject
  4. ##
  5. # Name of the required file
  6. attr_accessor :name
  7. ##
  8. # Creates a new Require that loads +name+ with +comment+
  9. def initialize(name, comment)
  10. super()
  11. @name = name.gsub(/'|"/, "") #'
  12. @top_level = nil
  13. self.comment = comment
  14. end
  15. def inspect # :nodoc:
  16. "#<%s:0x%x require '%s' in %s>" % [
  17. self.class,
  18. object_id,
  19. @name,
  20. parent_file_name,
  21. ]
  22. end
  23. def to_s # :nodoc:
  24. "require #{name} in: #{parent}"
  25. end
  26. ##
  27. # The RDoc::TopLevel corresponding to this require, or +nil+ if not found.
  28. def top_level
  29. @top_level ||= begin
  30. tl = RDoc::TopLevel.all_files_hash[name + '.rb']
  31. if tl.nil? and RDoc::TopLevel.all_files.first.full_name =~ %r(^lib/) then
  32. # second chance
  33. tl = RDoc::TopLevel.all_files_hash['lib/' + name + '.rb']
  34. end
  35. tl
  36. end
  37. end
  38. end