diff --git a/TODO.rdoc b/TODO.rdoc index da919118d9..c4dbc4cf5f 100644 --- a/TODO.rdoc +++ b/TODO.rdoc @@ -43,7 +43,6 @@ Forward Looking Statements applies. the middle of a method section. * RDoc::CodeObject * Move into own namespace - * Rename TopLevel to File * Rename Context to Container * Rename NormalClass to Class diff --git a/lib/rdoc.rb b/lib/rdoc.rb index b42059c712..1413486111 100644 --- a/lib/rdoc.rb +++ b/lib/rdoc.rb @@ -131,21 +131,21 @@ def self.load_yaml def self.home rdoc_dir = begin - File.expand_path('~/.rdoc') + ::File.expand_path('~/.rdoc') rescue ArgumentError end - if File.directory?(rdoc_dir) + if ::File.directory?(rdoc_dir) rdoc_dir else require 'fileutils' begin # XDG - xdg_data_home = ENV["XDG_DATA_HOME"] || File.join(File.expand_path("~"), '.local', 'share') - unless File.exist?(xdg_data_home) + xdg_data_home = ENV["XDG_DATA_HOME"] || ::File.join(::File.expand_path("~"), '.local', 'share') + unless ::File.exist?(xdg_data_home) FileUtils.mkdir_p xdg_data_home end - File.join xdg_data_home, "rdoc" + ::File.join xdg_data_home, "rdoc" rescue Errno::EACCES end end @@ -187,7 +187,8 @@ def self.home autoload :CodeObject, "#{__dir__}/rdoc/code_object" autoload :Context, "#{__dir__}/rdoc/code_object/context" - autoload :TopLevel, "#{__dir__}/rdoc/code_object/top_level" + autoload :File, "#{__dir__}/rdoc/code_object/file" + autoload :TopLevel, "#{__dir__}/rdoc/code_object/top_level" # @deprecated Use RDoc::File instead autoload :AnonClass, "#{__dir__}/rdoc/code_object/anon_class" autoload :ClassModule, "#{__dir__}/rdoc/code_object/class_module" diff --git a/lib/rdoc/code_object.rb b/lib/rdoc/code_object.rb index 388863b06c..c7b4d934f1 100644 --- a/lib/rdoc/code_object.rb +++ b/lib/rdoc/code_object.rb @@ -8,7 +8,7 @@ # Here's the tree of the CodeObject subclasses: # # * RDoc::Context -# * RDoc::TopLevel +# * RDoc::File # * RDoc::ClassModule # * RDoc::AnonClass (never used so far) # * RDoc::NormalClass @@ -291,7 +291,7 @@ def parent return @parent if @parent return nil unless @parent_name - if @parent_class == RDoc::TopLevel then + if @parent_class == RDoc::File then @parent = @store.add_file @parent_name else @parent = @store.find_class_or_module @parent_name @@ -314,12 +314,12 @@ def parent_name end ## - # Records the RDoc::TopLevel (file) where this code object was defined + # Records the RDoc::File (file) where this code object was defined - def record_location(top_level) + def record_location(file) @ignored = false @suppressed = false - @file = top_level + @file = file end ## diff --git a/lib/rdoc/code_object/any_method.rb b/lib/rdoc/code_object/any_method.rb index f56110ea11..dff39f186f 100644 --- a/lib/rdoc/code_object/any_method.rb +++ b/lib/rdoc/code_object/any_method.rb @@ -217,7 +217,7 @@ def marshal_load(array) name.join '::' end - @file = RDoc::TopLevel.new array[10] if version > 0 + @file = RDoc::File.new array[10] if version > 0 end ## diff --git a/lib/rdoc/code_object/attr.rb b/lib/rdoc/code_object/attr.rb index 969b18346d..e036437f7b 100644 --- a/lib/rdoc/code_object/attr.rb +++ b/lib/rdoc/code_object/attr.rb @@ -140,7 +140,7 @@ def marshal_load(array) @parent_class = array[9] @section_title = array[10] - @file = RDoc::TopLevel.new array[7] if version > 1 + @file = RDoc::File.new array[7] if version > 1 @parent_name ||= @full_name.split('#', 2).first end diff --git a/lib/rdoc/code_object/class_module.rb b/lib/rdoc/code_object/class_module.rb index f6b0abb2f5..e1a5ace51f 100644 --- a/lib/rdoc/code_object/class_module.rb +++ b/lib/rdoc/code_object/class_module.rb @@ -393,7 +393,7 @@ def marshal_load(array) # :nodoc: add_attribute attr attr.visibility = visibility - attr.record_location RDoc::TopLevel.new file + attr.record_location RDoc::File.new file end array[6].each do |constant, document, file| @@ -402,13 +402,13 @@ def marshal_load(array) # :nodoc: add_constant constant else constant = add_constant RDoc::Constant.new(constant, nil, RDoc::Comment.from_document(document)) - constant.record_location RDoc::TopLevel.new file + constant.record_location RDoc::File.new file end end array[7].each do |name, document, file| incl = add_include RDoc::Include.new(name, RDoc::Comment.from_document(document)) - incl.record_location RDoc::TopLevel.new file + incl.record_location RDoc::File.new file end array[8].each do |type, visibilities| @@ -417,7 +417,7 @@ def marshal_load(array) # :nodoc: methods.each do |name, file| method = RDoc::AnyMethod.new nil, name, singleton: type == 'class' - method.record_location RDoc::TopLevel.new file + method.record_location RDoc::File.new file add_method method end end @@ -425,7 +425,7 @@ def marshal_load(array) # :nodoc: array[9].each do |name, document, file| ext = add_extend RDoc::Extend.new(name, RDoc::Comment.from_document(document)) - ext.record_location RDoc::TopLevel.new file + ext.record_location RDoc::File.new file end if array[9] # Support Marshal version 1 sections = (array[10] || []).map do |section| @@ -438,7 +438,7 @@ def marshal_load(array) # :nodoc: @in_files = [] (array[11] || []).each do |filename| - record_location RDoc::TopLevel.new filename + record_location RDoc::File.new filename end @parent_name = array[12] @@ -632,7 +632,7 @@ def parse(comment_location) def path prefix = options.class_module_path_prefix return http_url unless prefix - File.join(prefix, http_url) + ::File.join(prefix, http_url) end ## @@ -795,7 +795,7 @@ def update_aliases cm_alias.name = const.name # Don't move top-level aliases under Object, they look ugly there - unless RDoc::TopLevel === cm_alias.parent then + unless RDoc::File === cm_alias.parent then cm_alias.parent = self cm_alias.full_name = nil # force update for new parent end diff --git a/lib/rdoc/code_object/constant.rb b/lib/rdoc/code_object/constant.rb index d5f54edb67..47e071d900 100644 --- a/lib/rdoc/code_object/constant.rb +++ b/lib/rdoc/code_object/constant.rb @@ -144,7 +144,7 @@ def marshal_load(array) @parent_class = array[8] @section_title = array[9] - @file = RDoc::TopLevel.new array[6] + @file = RDoc::File.new array[6] end ## diff --git a/lib/rdoc/code_object/context.rb b/lib/rdoc/code_object/context.rb index 3a4dd0ec68..36ef61fa34 100644 --- a/lib/rdoc/code_object/context.rb +++ b/lib/rdoc/code_object/context.rb @@ -297,7 +297,7 @@ def add_class(class_type, given_name, superclass = '::Object') # find the name & enclosing context if given_name =~ /^:+(\w+)$/ then full_name = $1 - enclosing = top_level + enclosing = file_context name = full_name.split(/:+/).last else full_name = child_name given_name @@ -361,7 +361,7 @@ def add_class(class_type, given_name, superclass = '::Object') klass = @store.classes_hash[full_name] if klass then - # if TopLevel, it may not be registered in the classes: + # if File, it may not be registered in the classes: enclosing.classes_hash[name] = klass # update the superclass if needed @@ -397,7 +397,7 @@ def add_class(class_type, given_name, superclass = '::Object') ## # Adds the class or module +mod+ to the modules or # classes Hash +self_hash+, and to +all_hash+ (either - # TopLevel::modules_hash or TopLevel::classes_hash), + # File::modules_hash or File::classes_hash), # unless #done_documenting is +true+. Sets the #parent of +mod+ # to +self+, and its #section to #current_section. Returns +mod+. @@ -568,7 +568,7 @@ def add_module_alias(from, from_name, to, file) def add_require(require) return require unless @document_self - if RDoc::TopLevel === self then + if RDoc::File === self then add_to @requires, require else parent.add_require require @@ -632,7 +632,7 @@ def any_content(includes = true) def child_name(name) if name =~ /^:+/ $' #' - elsif RDoc::TopLevel === self then + elsif RDoc::File === self then name else "#{self.full_name}::#{name}" @@ -894,14 +894,14 @@ def find_symbol_module(symbol) mod = searched.find_module_named(top) break unless mod result = @store.find_class_or_module "#{mod.full_name}::#{suffix}" - break if result || searched.is_a?(RDoc::TopLevel) + break if result || searched.is_a?(RDoc::File) searched = searched.parent end else searched = self while searched do result = searched.find_module_named(symbol) - break if result || searched.is_a?(RDoc::TopLevel) + break if result || searched.is_a?(RDoc::File) searched = searched.parent end end @@ -936,7 +936,7 @@ def http_url path = path.gsub(/<<\s*(\w*)/, 'from-\1') if path =~ /<" % [ + self.class, object_id, + base_name, + @modules.map { |n, m| m }, + @classes.map { |n, c| c } + ] + end + + ## + # Dumps this File for use by ri. See also #marshal_load + + def marshal_dump + [ + MARSHAL_VERSION, + @relative_name, + @parser, + parse(@comment), + ] + end + + ## + # Loads this File from +array+. + + def marshal_load(array) # :nodoc: + initialize array[1] + + @parser = array[2] + @comment = RDoc::Comment.from_document array[3] + end + + ## + # Returns the NormalClass "Object", creating it if not found. + # + # Records +self+ as a location in "Object". + + def object_class + @object_class ||= begin + oc = @store.find_class_named('Object') || add_class(RDoc::NormalClass, 'Object') + oc.record_location self + oc + end + end + + ## + # Path to this file for use with HTML generator output. + + def path + prefix = options.file_path_prefix + return http_url unless prefix + ::File.join(prefix, http_url) + end + + def pretty_print(q) # :nodoc: + q.group 2, "[#{self.class}: ", "]" do + q.text "base name: #{base_name.inspect}" + q.breakable + + items = @modules.map { |n, m| m } + items.concat @modules.map { |n, c| c } + q.seplist items do |mod| q.pp mod end + end + end + + ## + # Search record used by RDoc::Generator::JsonIndex + + def search_record + return unless @parser < RDoc::Parser::Text + + [ + page_name, + '', + page_name, + '', + path, + '', + snippet(@comment), + ] + end + + ## + # Is this File from a text file instead of a source code file? + + def text? + @parser and @parser.include? RDoc::Parser::Text + end + + def to_s # :nodoc: + "file #{full_name}" + end + +end diff --git a/lib/rdoc/code_object/require.rb b/lib/rdoc/code_object/require.rb index f47e3b1534..fcb721b3e1 100644 --- a/lib/rdoc/code_object/require.rb +++ b/lib/rdoc/code_object/require.rb @@ -15,7 +15,7 @@ class RDoc::Require < RDoc::CodeObject def initialize(name, comment) super() @name = name.gsub(/'|"/, "") #' - @top_level = nil + @file_context = nil self.comment = comment end @@ -33,19 +33,21 @@ def to_s # :nodoc: end ## - # The RDoc::TopLevel corresponding to this require, or +nil+ if not found. + # The RDoc::File corresponding to this require, or +nil+ if not found. - def top_level - @top_level ||= begin - tl = RDoc::TopLevel.all_files_hash[name + '.rb'] + def file_context + @file_context ||= begin + f = RDoc::File.all_files_hash[name + '.rb'] - if tl.nil? and RDoc::TopLevel.all_files.first.full_name =~ %r(^lib/) then + if f.nil? and RDoc::File.all_files.first.full_name =~ %r(^lib/) then # second chance - tl = RDoc::TopLevel.all_files_hash['lib/' + name + '.rb'] + f = RDoc::File.all_files_hash['lib/' + name + '.rb'] end - tl + f end end + alias_method :top_level, :file_context # :nodoc: + end diff --git a/lib/rdoc/code_object/top_level.rb b/lib/rdoc/code_object/top_level.rb index c1c003130e..87f4e4f4f0 100644 --- a/lib/rdoc/code_object/top_level.rb +++ b/lib/rdoc/code_object/top_level.rb @@ -1,266 +1,12 @@ # frozen_string_literal: true -## -# A TopLevel context is a representation of the contents of a single file - -class RDoc::TopLevel < RDoc::Context - - MARSHAL_VERSION = 0 # :nodoc: - - ## - # Relative name of this file - - attr_accessor :relative_name - - ## - # Absolute name of this file - - attr_accessor :absolute_name - - ## - # Base name of this file - - attr_reader :base_name - - ## - # Base name of this file without the extension - - attr_reader :page_name - - ## - # All the classes or modules that were declared in - # this file. These are assigned to either +#classes_hash+ - # or +#modules_hash+ once we know what they really are. - - attr_reader :classes_or_modules - - ## - # The parser class that processed this file - - attr_reader :parser - - ## - # Creates a new TopLevel for the file at +absolute_name+. If documentation - # is being generated outside the source dir +relative_name+ is relative to - # the source directory. - - def initialize(absolute_name, relative_name = absolute_name) - super() - @name = nil - @absolute_name = absolute_name - @relative_name = relative_name - @parser = nil - - if relative_name - @base_name = File.basename(relative_name) - @page_name = @base_name.sub(/\.(rb|rdoc|txt|md)\z/i, '') - else - @base_name = nil - @page_name = nil - end - - @classes_or_modules = [] - end - - ## - # Sets the parser for this toplevel context, also the store. - - def parser=(val) - @parser = val - @store.update_parser_of_file(absolute_name, val) if @store - @parser - end - - ## - # An RDoc::TopLevel is equal to another with the same relative_name - - def ==(other) - self.class === other and @relative_name == other.relative_name - end - - alias eql? == - - ## - # Adds +an_alias+ to +Object+ instead of +self+. - - def add_alias(an_alias) - object_class.record_location self - return an_alias unless @document_self - object_class.add_alias an_alias - end - - ## - # Adds +constant+ to +Object+ instead of +self+. - - def add_constant(constant) - object_class.record_location self - return constant unless @document_self - object_class.add_constant constant - end - - ## - # Adds +include+ to +Object+ instead of +self+. - - def add_include(include) - object_class.record_location self - return include unless @document_self - object_class.add_include include - end - - ## - # Adds +method+ to +Object+ instead of +self+. - - def add_method(method) - object_class.record_location self - return method unless @document_self - object_class.add_method method - end - ## - # Adds class or module +mod+. Used in the building phase - # by the Ruby parser. +require_relative "file" - def add_to_classes_or_modules(mod) - @classes_or_modules << mod - end - - alias name base_name - - ## - # See RDoc::TopLevel::find_class_or_module - #-- - # TODO Why do we search through all classes/modules found, not just the - # ones of this instance? - - def find_class_or_module(name) - @store.find_class_or_module name - end - - ## - # Finds a class or module named +symbol+ - - def find_local_symbol(symbol) - find_class_or_module(symbol) || super - end - - ## - # Finds a module or class with +name+ - - def find_module_named(name) - find_class_or_module(name) - end - - ## - # Returns the relative name of this file - - def full_name - @relative_name - end - - ## - # An RDoc::TopLevel has the same hash as another with the same - # relative_name - - def hash - @relative_name.hash - end - - ## - # URL for this with a +prefix+ - - def http_url - @relative_name.tr('.', '_') + '.html' - end - - def inspect # :nodoc: - "#<%s:0x%x %p modules: %p classes: %p>" % [ - self.class, object_id, - base_name, - @modules.map { |n, m| m }, - @classes.map { |n, c| c } - ] - end - - ## - # Dumps this TopLevel for use by ri. See also #marshal_load - - def marshal_dump - [ - MARSHAL_VERSION, - @relative_name, - @parser, - parse(@comment), - ] - end - - ## - # Loads this TopLevel from +array+. - - def marshal_load(array) # :nodoc: - initialize array[1] - - @parser = array[2] - @comment = RDoc::Comment.from_document array[3] - end - - ## - # Returns the NormalClass "Object", creating it if not found. - # - # Records +self+ as a location in "Object". - - def object_class - @object_class ||= begin - oc = @store.find_class_named('Object') || add_class(RDoc::NormalClass, 'Object') - oc.record_location self - oc - end - end - - ## - # Path to this file for use with HTML generator output. - - def path - prefix = options.file_path_prefix - return http_url unless prefix - File.join(prefix, http_url) - end - - def pretty_print(q) # :nodoc: - q.group 2, "[#{self.class}: ", "]" do - q.text "base name: #{base_name.inspect}" - q.breakable - - items = @modules.map { |n, m| m } - items.concat @modules.map { |n, c| c } - q.seplist items do |mod| q.pp mod end - end - end - - ## - # Search record used by RDoc::Generator::JsonIndex - - def search_record - return unless @parser < RDoc::Parser::Text - - [ - page_name, - '', - page_name, - '', - path, - '', - snippet(@comment), - ] - end - - ## - # Is this TopLevel from a text file instead of a source code file? - - def text? - @parser and @parser.include? RDoc::Parser::Text - end - - def to_s # :nodoc: - "file #{full_name}" - end +## +# RDoc::TopLevel is deprecated and will be removed in a future version. +# Use RDoc::File instead. +module RDoc + TopLevel = File # :nodoc: + deprecate_constant :TopLevel end diff --git a/lib/rdoc/comment.rb b/lib/rdoc/comment.rb index 5d71cd35bd..87783bee3c 100644 --- a/lib/rdoc/comment.rb +++ b/lib/rdoc/comment.rb @@ -19,7 +19,7 @@ class RDoc::Comment attr_reader :format ## - # The RDoc::TopLevel this comment was found in + # The RDoc::File this comment was found in attr_accessor :location @@ -50,7 +50,7 @@ class RDoc::Comment attr_writer :document ## - # Creates a new comment with +text+ that is found in the RDoc::TopLevel + # Creates a new comment with +text+ that is found in the RDoc::File # +location+. def initialize(text = nil, location = nil, language = nil) @@ -246,7 +246,7 @@ class << self def from_document(document) # :nodoc: comment = RDoc::Comment.new('') comment.document = document - comment.location = RDoc::TopLevel.new(document.file) if document.file + comment.location = RDoc::File.new(document.file) if document.file comment end diff --git a/lib/rdoc/cross_reference.rb b/lib/rdoc/cross_reference.rb index 1f33538b73..4b2a03be78 100644 --- a/lib/rdoc/cross_reference.rb +++ b/lib/rdoc/cross_reference.rb @@ -159,7 +159,7 @@ def resolve_method(name) end if container then - unless RDoc::TopLevel === container then + unless RDoc::File === container then if '.' == type then if 'new' == method then # AnyClassName.new will be class method ref = container.find_local_symbol method diff --git a/lib/rdoc/encoding.rb b/lib/rdoc/encoding.rb index 78dbe87d0c..4804e0037c 100644 --- a/lib/rdoc/encoding.rb +++ b/lib/rdoc/encoding.rb @@ -30,7 +30,7 @@ module RDoc::Encoding # unknown character in the target encoding will be replaced with '?' def self.read_file(filename, encoding, force_transcode = false) - content = File.open filename, "rb" do |f| f.read end + content = ::File.open filename, "rb" do |f| f.read end content.gsub!("\r\n", "\n") if RUBY_PLATFORM =~ /mswin|mingw/ utf8 = content.sub!(/\A\xef\xbb\xbf/, '') diff --git a/lib/rdoc/erbio.rb b/lib/rdoc/erbio.rb index e955eed811..ea5a0f6743 100644 --- a/lib/rdoc/erbio.rb +++ b/lib/rdoc/erbio.rb @@ -9,7 +9,7 @@ # # erbio = RDoc::ERBIO.new '<%= "hello world" %>', nil, nil # -# File.open 'hello.txt', 'w' do |io| +# ::File.open 'hello.txt', 'w' do |io| # erbio.result binding # end # diff --git a/lib/rdoc/generator.rb b/lib/rdoc/generator.rb index e8a14d4a66..eb4be6bbbd 100644 --- a/lib/rdoc/generator.rb +++ b/lib/rdoc/generator.rb @@ -31,9 +31,9 @@ # #initialize with an RDoc::Store instance and an RDoc::Options instance. # # The RDoc::Store instance holds documentation for parsed source code. In -# RDoc 3 and earlier the RDoc::TopLevel class held this data. When upgrading +# RDoc 3 and earlier the RDoc::File class held this data. When upgrading # a generator from RDoc 3 and earlier you should only need to replace -# RDoc::TopLevel with the store instance. +# RDoc::File with the store instance. # # RDoc will then call #generate on the generator instance. You can use the # various methods on RDoc::Store and in the RDoc::CodeObject tree to create diff --git a/lib/rdoc/generator/aliki.rb b/lib/rdoc/generator/aliki.rb index faa310451c..5ce7f1d138 100644 --- a/lib/rdoc/generator/aliki.rb +++ b/lib/rdoc/generator/aliki.rb @@ -11,7 +11,7 @@ class RDoc::Generator::Aliki < RDoc::Generator::Darkfish def initialize(store, options) super - aliki_template_dir = File.expand_path(File.join(__dir__, 'template', 'aliki')) + aliki_template_dir = ::File.expand_path(::File.join(__dir__, 'template', 'aliki')) @template_dir = Pathname.new(aliki_template_dir) end @@ -31,8 +31,8 @@ def write_style_sheet end Dir[(@template_dir + 'js/**/*').to_s].each do |path| - next if File.directory?(path) - next if File.basename(path).start_with?('.') + next if ::File.directory?(path) + next if ::File.basename(path).start_with?('.') dst = Pathname.new(path).relative_path_from(@template_dir) diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index 9679216b95..fea0b3c11b 100644 --- a/lib/rdoc/generator/darkfish.rb +++ b/lib/rdoc/generator/darkfish.rb @@ -203,8 +203,8 @@ def write_style_sheet end Dir[(@template_dir + "{js,images}/**/*").to_s].each do |path| - next if File.directory? path - next if File.basename(path) =~ /^\./ + next if ::File.directory? path + next if ::File.basename(path) =~ /^\./ dst = Pathname.new(path).relative_path_from @template_dir @@ -213,7 +213,7 @@ def write_style_sheet end ## - # Build the initial indices and output objects based on an array of TopLevel + # Build the initial indices and output objects based on an array of File # objects containing the extracted information. def generate @@ -246,16 +246,16 @@ def copy_static fu_options = { :verbose => $DEBUG_RDOC, :noop => @dry_run } @options.static_path.each do |path| - unless File.directory? path then + unless ::File.directory? path then FileUtils.install path, @outputdir, **fu_options.merge(:mode => 0644) next end Dir.chdir path do - Dir[File.join('**', '*')].each do |entry| + Dir[::File.join('**', '*')].each do |entry| dest_file = @outputdir + entry - if File.directory? entry then + if ::File.directory? entry then FileUtils.mkdir_p entry, **fu_options else FileUtils.install entry, dest_file, **fu_options.merge(:mode => 0644) @@ -555,7 +555,7 @@ def install_rdoc_static_file(source, destination, options) # :nodoc: return unless source.exist? begin - FileUtils.mkdir_p File.dirname(destination), **options + FileUtils.mkdir_p ::File.dirname(destination), **options begin FileUtils.ln source, destination, **options @@ -688,7 +688,7 @@ def template_for(file, page = true, klass = ERB) template = file.read template = template.encode @options.encoding - file_var = File.basename(file).sub(/\..*/, '') + file_var = ::File.basename(file).sub(/\..*/, '') erbout = "_erbout_#{file_var}" end diff --git a/lib/rdoc/generator/json_index.rb b/lib/rdoc/generator/json_index.rb index 065caa47ea..ec5fa8e0a8 100644 --- a/lib/rdoc/generator/json_index.rb +++ b/lib/rdoc/generator/json_index.rb @@ -81,7 +81,7 @@ class RDoc::Generator::JsonIndex ## # Where the search index lives in the generated output - SEARCH_INDEX_FILE = File.join 'js', 'search_index.js' + SEARCH_INDEX_FILE = ::File.join 'js', 'search_index.js' attr_reader :index # :nodoc: @@ -94,7 +94,7 @@ def initialize(parent_generator, options) @store = parent_generator.store @options = options - @template_dir = File.expand_path '../template/json_index', __FILE__ + @template_dir = ::File.expand_path '../template/json_index', __FILE__ @base_dir = @parent_generator.base_dir @classes = nil @@ -151,7 +151,7 @@ def generate Dir.chdir @template_dir do Dir['**/*.js'].each do |source| - dest = File.join out_dir, source + dest = ::File.join out_dir, source FileUtils.install source, dest, :mode => 0644, :preserve => true, :verbose => $DEBUG_RDOC end @@ -176,7 +176,7 @@ def generate_gzipped debug_msg "Writing gzipped search index to %s" % outfile Zlib::GzipWriter.open(outfile) do |gz| - gz.mtime = File.mtime(search_index_file) + gz.mtime = ::File.mtime(search_index_file) gz.orig_name = search_index_file.basename.to_s gz.write search_index gz.close @@ -194,7 +194,7 @@ def generate_gzipped debug_msg "Writing gzipped file to %s" % outfile Zlib::GzipWriter.open(outfile) do |gz| - gz.mtime = File.mtime(dest) + gz.mtime = ::File.mtime(dest) gz.orig_name = dest.basename.to_s gz.write data gz.close diff --git a/lib/rdoc/generator/markup.rb b/lib/rdoc/generator/markup.rb index 1c39687040..0f80db634c 100644 --- a/lib/rdoc/generator/markup.rb +++ b/lib/rdoc/generator/markup.rb @@ -61,7 +61,7 @@ def cvs_url(url, full_path) def canonical_url options = @store.options if path - File.join(options.canonical_root, path.to_s) + ::File.join(options.canonical_root, path.to_s) else options.canonical_root end @@ -152,7 +152,7 @@ class RDoc::Context::Section end -class RDoc::TopLevel +class RDoc::File ## # Returns a URL for this source file on some web repository. Use the -W diff --git a/lib/rdoc/generator/pot.rb b/lib/rdoc/generator/pot.rb index a20fde077b..4d599d797d 100644 --- a/lib/rdoc/generator/pot.rb +++ b/lib/rdoc/generator/pot.rb @@ -76,7 +76,7 @@ def initialize(store, options) #:not-new: def generate po = extract_messages pot_path = 'rdoc.pot' - File.open(pot_path, "w") do |pot| + ::File.open(pot_path, "w") do |pot| pot.print(po.to_s) end end diff --git a/lib/rdoc/generator/template/aliki/_head.rhtml b/lib/rdoc/generator/template/aliki/_head.rhtml index d7392f3487..1327b2f0cf 100644 --- a/lib/rdoc/generator/template/aliki/_head.rhtml +++ b/lib/rdoc/generator/template/aliki/_head.rhtml @@ -152,7 +152,7 @@ <%- @options.template_stylesheets.each do |stylesheet| %> <%- end %> diff --git a/lib/rdoc/generator/template/darkfish/_head.rhtml b/lib/rdoc/generator/template/darkfish/_head.rhtml index c90635877a..aed0e661c7 100644 --- a/lib/rdoc/generator/template/darkfish/_head.rhtml +++ b/lib/rdoc/generator/template/darkfish/_head.rhtml @@ -39,5 +39,5 @@ <%- @options.template_stylesheets.each do |stylesheet| %> - + <%- end %> diff --git a/lib/rdoc/i18n/locale.rb b/lib/rdoc/i18n/locale.rb index 6a70d6c986..478feba56e 100644 --- a/lib/rdoc/i18n/locale.rb +++ b/lib/rdoc/i18n/locale.rb @@ -64,11 +64,11 @@ def load(locale_directory) return false if @name.nil? po_file_candidates = [ - File.join(locale_directory, @name, 'rdoc.po'), - File.join(locale_directory, "#{@name}.po"), + ::File.join(locale_directory, @name, 'rdoc.po'), + ::File.join(locale_directory, "#{@name}.po"), ] po_file = po_file_candidates.find do |po_file_candidate| - File.exist?(po_file_candidate) + ::File.exist?(po_file_candidate) end return false unless po_file diff --git a/lib/rdoc/markdown.kpeg b/lib/rdoc/markdown.kpeg index 46c8f07f41..d6c01c3a49 100644 --- a/lib/rdoc/markdown.kpeg +++ b/lib/rdoc/markdown.kpeg @@ -16,7 +16,7 @@ # # Here is a brief example of using this parse to read a markdown file by hand. # -# data = File.read("README.md") +# data = ::File.read("README.md") # formatter = RDoc::Markup::ToHtml.new(RDoc::Options.new, nil) # html = RDoc::Markdown.parse(data).accept(formatter) # diff --git a/lib/rdoc/markdown.rb b/lib/rdoc/markdown.rb index e9cb35c244..c440ef5f95 100644 --- a/lib/rdoc/markdown.rb +++ b/lib/rdoc/markdown.rb @@ -13,7 +13,7 @@ # # Here is a brief example of using this parse to read a markdown file by hand. # -# data = File.read("README.md") +# data = ::File.read("README.md") # formatter = RDoc::Markup::ToHtml.new(RDoc::Options.new, nil) # html = RDoc::Markdown.parse(data).accept(formatter) # diff --git a/lib/rdoc/markup/document.rb b/lib/rdoc/markup/document.rb index 399cfe8e3e..6ce1c31588 100644 --- a/lib/rdoc/markup/document.rb +++ b/lib/rdoc/markup/document.rb @@ -96,7 +96,7 @@ def empty? def file=(location) @file = case location - when RDoc::TopLevel then + when RDoc::File then location.relative_name else location diff --git a/lib/rdoc/markup/formatter.rb b/lib/rdoc/markup/formatter.rb index 8c55a37b06..aa8348c056 100644 --- a/lib/rdoc/markup/formatter.rb +++ b/lib/rdoc/markup/formatter.rb @@ -22,8 +22,8 @@ class RDoc::Markup::Formatter # Converts a target url to one that is relative to a given path def self.gen_relative_url(path, target) - from = File.dirname path - to, to_file = File.split target + from = ::File.dirname path + to, to_file = ::File.split target from = from.split "/" to = to.split "/" @@ -39,7 +39,7 @@ def self.gen_relative_url(path, target) from.fill ".." from.concat to from << to_file - File.join(*from) + ::File.join(*from) end ## diff --git a/lib/rdoc/markup/pre_process.rb b/lib/rdoc/markup/pre_process.rb index 9e36d7f0cd..0d7aedae5f 100644 --- a/lib/rdoc/markup/pre_process.rb +++ b/lib/rdoc/markup/pre_process.rb @@ -330,10 +330,10 @@ def include_file(name, indent, encoding) # and then in each of the directories specified in the RDOC_INCLUDE path def find_include_file(name) - to_search = [File.dirname(@input_file_name)].concat @include_path + to_search = [::File.dirname(@input_file_name)].concat @include_path to_search.each do |dir| - full_name = File.join(dir, name) - stat = File.stat(full_name) rescue next + full_name = ::File.join(dir, name) + stat = ::File.stat(full_name) rescue next return full_name if stat.readable? end nil diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb index c05a3b5b17..0e8ca845c9 100644 --- a/lib/rdoc/markup/to_html_crossref.rb +++ b/lib/rdoc/markup/to_html_crossref.rb @@ -164,7 +164,7 @@ def link(name, text, code = true, rdoc_ref: false) else path = ref ? ref.as_href(@from_path) : +"" - if code and RDoc::CodeObject === ref and !(RDoc::TopLevel === ref) + if code and RDoc::CodeObject === ref and !(RDoc::File === ref) text = "#{CGI.escapeHTML text}" end diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index c3f16d37b1..580c963ca7 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -556,8 +556,8 @@ def ==(other) # :nodoc: def check_files @files.delete_if do |file| - if File.exist? file then - if File.readable? file then + if ::File.exist? file then + if ::File.readable? file then false else warn "file '#{file}' not readable" @@ -726,7 +726,7 @@ def parse(argv) opts = OptionParser.new do |opt| @option_parser = opt - opt.program_name = File.basename $0 + opt.program_name = ::File.basename $0 opt.version = RDoc::VERSION opt.release = nil opt.summary_indent = ' ' * 4 @@ -789,17 +789,17 @@ def parse(argv) end opt.accept Directory do |directory| - directory = File.expand_path directory + directory = ::File.expand_path directory - raise OptionParser::InvalidArgument unless File.directory? directory + raise OptionParser::InvalidArgument unless ::File.directory? directory directory end opt.accept Path do |path| - path = File.expand_path path + path = ::File.expand_path path - raise OptionParser::InvalidArgument unless File.exist? path + raise OptionParser::InvalidArgument unless ::File.exist? path path end @@ -810,9 +810,9 @@ def parse(argv) end paths.map do |path| - path = File.expand_path path + path = ::File.expand_path path - raise OptionParser::InvalidArgument unless File.exist? path + raise OptionParser::InvalidArgument unless ::File.exist? path path end @@ -1349,12 +1349,12 @@ def setup_generator(generator_name = @generator_name) # Finds the template dir for +template+ def template_dir_for(template) - template_path = File.join 'rdoc', 'generator', 'template', template + template_path = ::File.join 'rdoc', 'generator', 'template', template $LOAD_PATH.map do |path| - File.join File.expand_path(path), template_path + ::File.join ::File.expand_path(path), template_path end.find do |dir| - File.directory? dir + ::File.directory? dir end end @@ -1388,7 +1388,7 @@ def warn(message) def write_options RDoc.load_yaml - File.open '.rdoc_options', 'w' do |io| + ::File.open '.rdoc_options', 'w' do |io| io.set_encoding Encoding::UTF_8 io.print to_yaml @@ -1400,13 +1400,13 @@ def write_options # new RDoc::Options instance. def self.load_options - options_file = File.expand_path '.rdoc_options' - return RDoc::Options.new unless File.exist? options_file + options_file = ::File.expand_path '.rdoc_options' + return RDoc::Options.new unless ::File.exist? options_file RDoc.load_yaml begin - options = YAML.safe_load File.read('.rdoc_options'), permitted_classes: [RDoc::Options, Symbol] + options = YAML.safe_load ::File.read('.rdoc_options'), permitted_classes: [RDoc::Options, Symbol] rescue Psych::SyntaxError raise RDoc::Error, "#{options_file} is not a valid rdoc options file" end diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb index 2ac960e089..0e7047d114 100644 --- a/lib/rdoc/parser.rb +++ b/lib/rdoc/parser.rb @@ -3,13 +3,13 @@ ## # A parser is simple a class that subclasses RDoc::Parser and implements #scan -# to fill in an RDoc::TopLevel with parsed data. +# to fill in an RDoc::File with parsed data. # -# The initialize method takes an RDoc::TopLevel to fill with parsed content, +# The initialize method takes an RDoc::File to fill with parsed content, # the name of the file to be parsed, the content of the file, an RDoc::Options # object and an RDoc::Stats object to inform the user of parsed items. The # scan method is then called to parse the file and must return the -# RDoc::TopLevel object. By calling super these items will be set for you. +# RDoc::File object. By calling super these items will be set for you. # # In order to be used by RDoc the parser needs to register the file extensions # it can parse. Use ::parse_files_matching to register extensions. @@ -19,14 +19,14 @@ # class RDoc::Parser::Xyz < RDoc::Parser # parse_files_matching /\.xyz$/ # -# def initialize top_level, file_name, content, options, stats +# def initialize file, file_name, content, options, stats # super # # # extra initialization if needed # end # # def scan -# # parse file and fill in @top_level +# # parse file and fill in @file # end # end @@ -74,7 +74,7 @@ def self.alias_extension(old_ext, new_ext) def self.binary?(file) return false if file =~ /\.(rdoc|txt)$/ - s = File.read(file, 1024) or return false + s = ::File.read(file, 1024) or return false return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00") @@ -82,7 +82,7 @@ def self.binary?(file) s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024. encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1] mode = "rb:#{encoding}" if encoding - s = File.open(file, mode) {|f| f.gets(nil, 1024)} + s = ::File.open(file, mode) {|f| f.gets(nil, 1024)} not s.valid_encoding? end @@ -92,7 +92,7 @@ def self.binary?(file) # http://www.garykessler.net/library/file_sigs.html def self.zip?(file) - zip_signature = File.read file, 4 + zip_signature = ::File.read file, 4 zip_signature == "PK\x03\x04" or zip_signature == "PK\x05\x06" or @@ -121,7 +121,7 @@ def self.can_parse_by_name(file_name) _, parser = RDoc::Parser.parsers.find { |regexp,| regexp =~ file_name } # The default parser must not parse binary files - ext_name = File.extname file_name + ext_name = ::File.extname file_name return parser if ext_name.empty? if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/ then @@ -141,7 +141,7 @@ def self.can_parse_by_name(file_name) # Returns the file type from the modeline in +file_name+ def self.check_modeline(file_name) - line = File.open file_name do |io| + line = ::File.open file_name do |io| io.gets end @@ -166,8 +166,8 @@ def self.check_modeline(file_name) # Finds and instantiates the correct parser for the given +file_name+ and # +content+. - def self.for(top_level, content, options, stats) - file_name = top_level.absolute_name + def self.for(file, content, options, stats) + file_name = file.absolute_name return if binary? file_name parser = use_markup content @@ -191,7 +191,7 @@ def self.for(top_level, content, options, stats) content = remove_modeline content - parser.new top_level, content, options, stats + parser.new file, content, options, stats rescue SystemCallError nil end @@ -247,17 +247,17 @@ def self.use_markup(content) end ## - # Creates a new Parser storing +top_level+, +file_name+, +content+, + # Creates a new Parser storing +file+, +file_name+, +content+, # +options+ and +stats+ in instance variables. In +@preprocess+ an # RDoc::Markup::PreProcess object is created which allows processing of # directives. - def initialize(top_level, content, options, stats) - @top_level = top_level - @top_level.parser = self.class - @store = @top_level.store + def initialize(file, content, options, stats) + @file = file + @file.parser = self.class + @store = @file.store - @file_name = top_level.absolute_name + @file_name = file.absolute_name @content = content @options = options @stats = stats diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb index 603f28dfe1..e0aaf1f61b 100644 --- a/lib/rdoc/parser/c.rb +++ b/lib/rdoc/parser/c.rb @@ -160,20 +160,20 @@ class RDoc::Parser::C < RDoc::Parser attr_reader :singleton_classes ## - # The TopLevel items in the parsed file belong to + # The File items in the parsed file belong to - attr_reader :top_level + attr_reader :file ## # Prepares for parsing a C file. See RDoc::Parser#initialize for details on # the arguments. - def initialize(top_level, content, options, stats) + def initialize(file, content, options, stats) super @known_classes = RDoc::KNOWN_CLASSES.dup @content = handle_tab_width handle_ifdefs_in @content - @file_dir = File.dirname @file_name + @file_dir = ::File.dirname @file_name @classes = load_variable_map :c_class_variables @singleton_classes = load_variable_map :c_singleton_class_variables @@ -249,7 +249,7 @@ def do_aliases def add_alias(var_name, class_obj, old_name, new_name, comment) al = RDoc::Alias.new '', old_name, new_name, comment, singleton: @singleton_classes.key?(var_name) - al.record_location @top_level + al.record_location @file class_obj.add_alias al @stats.add_alias al al @@ -443,9 +443,9 @@ def do_includes next unless cls = @classes[c] m = @known_classes[m] || m - comment = new_comment '', @top_level, :c + comment = new_comment '', @file, :c incl = cls.add_include RDoc::Include.new(m, comment) - incl.record_location @top_level + incl.record_location @file end end @@ -525,7 +525,7 @@ def find_alias_comment(class_name, new_name, old_name) \s*"#{Regexp.escape new_name}"\s*, \s*"#{Regexp.escape old_name}"\s*\);%xm - new_comment($1 || '', @top_level, :c) + new_comment($1 || '', @file, :c) end ## @@ -564,7 +564,7 @@ def find_attr_comment(var_name, attr_name, read = nil, write = nil) '' end - new_comment comment, @top_level, :c + new_comment comment, @file, :c end ## @@ -603,7 +603,7 @@ def find_body(class_name, meth_name, meth_obj, file_content, quiet = false) case type when :func_def - comment = new_comment args[0], @top_level, :c + comment = new_comment args[0], @file, :c body = args[1] offset, = args[2] @@ -630,7 +630,7 @@ def find_body(class_name, meth_name, meth_obj, file_content, quiet = false) body when :macro_def - comment = new_comment args[0], @top_level, :c + comment = new_comment args[0], @file, :c body = args[1] offset, = args[2] @@ -676,13 +676,13 @@ def find_body(class_name, meth_name, meth_obj, file_content, quiet = false) def find_class(raw_name, name, base_name = nil) unless @classes[raw_name] if raw_name =~ /^rb_m/ - container = @top_level.add_module RDoc::NormalModule, name + container = @file.add_module RDoc::NormalModule, name else - container = @top_level.add_class RDoc::NormalClass, name + container = @file.add_class RDoc::NormalClass, name end container.name = base_name if base_name - container.record_location @top_level + container.record_location @file @classes[raw_name] = container end @classes[raw_name] @@ -736,11 +736,11 @@ def find_class_comment(class_name, class_mod) comment = '' end - comment = new_comment comment, @top_level, :c + comment = new_comment comment, @file, :c look_for_directives_in class_mod, comment - class_mod.add_comment comment, @top_level + class_mod.add_comment comment, @file end ## @@ -794,7 +794,7 @@ def find_const_comment(type, const_name, class_name = nil) table[const_name] || '' - new_comment comment, @top_level, :c + new_comment comment, @file, :c end ## @@ -822,7 +822,7 @@ def find_override_comment(class_name, meth_obj) return unless comment - new_comment comment, @top_level, :c + new_comment comment, @file, :c end ## @@ -849,7 +849,7 @@ def handle_attr(var_name, attr_name, read, write) attr = RDoc::Attr.new '', name, rw, comment - attr.record_location @top_level + attr.record_location @file class_obj.add_attribute attr @stats.add_attribute attr end @@ -878,7 +878,7 @@ def handle_class_module(var_name, type, class_name, parent, in_module) return end else - enclosure = @top_level + enclosure = @file end if type == :class then @@ -897,7 +897,7 @@ def handle_class_module(var_name, type, class_name, parent, in_module) cm = enclosure.add_module RDoc::NormalModule, class_name end - cm.record_location enclosure.top_level + cm.record_location enclosure.file_context find_class_comment cm.full_name, cm @@ -955,7 +955,7 @@ def handle_constants(type, var_name, const_name, definition) new_comment = "#{$1}#{new_comment.lstrip}" - new_comment = self.new_comment(new_comment, @top_level, :c) + new_comment = self.new_comment(new_comment, @file, :c) con = RDoc::Constant.new const_name, new_definition, new_comment else @@ -965,7 +965,7 @@ def handle_constants(type, var_name, const_name, definition) con = RDoc::Constant.new const_name, definition, comment end - con.record_location @top_level + con.record_location @file @stats.add_constant con class_obj.add_constant con end @@ -1011,10 +1011,10 @@ def handle_method(type, var_name, meth_name, function, param_count, p_count = Integer(param_count) rescue -1 if source_file then - file_name = File.join @file_dir, source_file + file_name = ::File.join @file_dir, source_file - if File.exist? file_name then - file_content = File.read file_name + if ::File.exist? file_name then + file_content = ::File.read file_name else @options.warn "unknown source #{source_file} for #{meth_name} in #{@file_name}" end @@ -1035,7 +1035,7 @@ def handle_method(type, var_name, meth_name, function, param_count, end - meth_obj.record_location @top_level + meth_obj.record_location @file if meth_obj.section_title class_obj.temporary_section = class_obj.add_section(meth_obj.section_title) @@ -1196,7 +1196,7 @@ def remove_commented_out_lines ## # Extracts the classes, modules, methods, attributes, constants and aliases - # from a C file and returns an RDoc::TopLevel for this file + # from a C file and returns an RDoc::File for this file def scan remove_commented_out_lines @@ -1212,7 +1212,7 @@ def scan @store.add_c_variables self - @top_level + @file end ## diff --git a/lib/rdoc/parser/changelog.rb b/lib/rdoc/parser/changelog.rb index b8ad2393b1..f9ff4d4504 100644 --- a/lib/rdoc/parser/changelog.rb +++ b/lib/rdoc/parser/changelog.rb @@ -44,9 +44,9 @@ def continue_entry_body(entry_body, continuation) def create_document(groups) doc = RDoc::Markup::Document.new doc.omit_headings_below = 2 - doc.file = @top_level + doc.file = @file - doc << RDoc::Markup::Heading.new(1, File.basename(@file_name)) + doc << RDoc::Markup::Heading.new(1, ::File.basename(@file_name)) doc << RDoc::Markup::BlankLine.new groups.sort_by do |day,| day end.reverse_each do |day, entries| @@ -212,9 +212,9 @@ def scan doc = create_document grouped_entries comment = RDoc::Comment.new(@content) comment.document = doc - @top_level.comment = comment + @file.comment = comment - @top_level + @file end ## diff --git a/lib/rdoc/parser/markdown.rb b/lib/rdoc/parser/markdown.rb index 3c316227b9..cd70d4e203 100644 --- a/lib/rdoc/parser/markdown.rb +++ b/lib/rdoc/parser/markdown.rb @@ -10,13 +10,13 @@ class RDoc::Parser::Markdown < RDoc::Parser parse_files_matching(/\.(md|markdown)(?:\.[^.]+)?$/) ## - # Creates an Markdown-format TopLevel for the given file. + # Creates an Markdown-format File for the given file. def scan - comment = RDoc::Comment.new @content, @top_level + comment = RDoc::Comment.new @content, @file comment.format = 'markdown' - @top_level.comment = comment + @file.comment = comment end end diff --git a/lib/rdoc/parser/prism_ruby.rb b/lib/rdoc/parser/prism_ruby.rb index 56da6ac227..be01af813d 100644 --- a/lib/rdoc/parser/prism_ruby.rb +++ b/lib/rdoc/parser/prism_ruby.rb @@ -18,7 +18,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser attr_accessor :visibility attr_reader :container, :singleton - def initialize(top_level, content, options, stats) + def initialize(file, content, options, stats) super content = handle_tab_width(content) @@ -31,8 +31,8 @@ def initialize(top_level, content, options, stats) @track_visibility = :nodoc != @options.visibility @encoding = @options.encoding - @module_nesting = [[top_level, false]] - @container = top_level + @module_nesting = [[file, false]] + @container = file @visibility = :public @singleton = false @in_proc_block = false @@ -80,10 +80,10 @@ def with_container(container, singleton: false) def record_location(container) # :nodoc: case container when RDoc::ClassModule then - @top_level.add_to_classes_or_modules container + @file.add_to_classes_or_modules container end - container.record_location @top_level + container.record_location @file end # Scans this Ruby file for Ruby constructs @@ -96,14 +96,14 @@ def scan @line_nodes = {} prepare_line_nodes(@program_node) prepare_comments(result.comments) - return if @top_level.done_documenting + return if @file.done_documenting @first_non_meta_comment_start_line = nil if (_line_no, start_line = @unprocessed_comments.first) @first_non_meta_comment_start_line = start_line if start_line < @program_node.location.start_line end - @program_node.accept(RDocVisitor.new(self, @top_level, @store)) + @program_node.accept(RDocVisitor.new(self, @file, @store)) process_comments_until(@lines.size + 1) end @@ -323,7 +323,7 @@ def process_comments_until(line_no_until) while !@unprocessed_comments.empty? && @unprocessed_comments.first[0] <= line_no_until line_no, start_line, text = @unprocessed_comments.shift if @markup == 'tomdoc' - comment = RDoc::Comment.new(text, @top_level, :ruby) + comment = RDoc::Comment.new(text, @file, :ruby) comment.format = 'tomdoc' parse_comment_tomdoc(@container, comment, line_no, start_line) @preprocess.run_post_processes(comment, @container) @@ -354,7 +354,7 @@ def consecutive_comment(line_no) def parse_comment_text_to_directives(comment_text, start_line) # :nodoc: comment_text, directives = @preprocess.parse_comment(comment_text, start_line, :ruby) - comment = RDoc::Comment.new(comment_text, @top_level, :ruby) + comment = RDoc::Comment.new(comment_text, @file, :ruby) comment.normalized = true comment.line = start_line markup, = directives['markup'] @@ -378,7 +378,7 @@ def slice_tokens(start_pos, end_pos) # :nodoc: def file_line_comment_token(line_no) # :nodoc: position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no - 1, 0, :on_comment) - position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}" + position_comment[:text] = "# File #{@file.relative_name}, line #{line_no}" position_comment end @@ -586,7 +586,7 @@ def find_or_create_module_path(module_name, create_mode) end } if root_name.empty? - mod = @top_level + mod = @file else @module_nesting.reverse_each do |nesting, singleton| next if singleton @@ -617,7 +617,7 @@ def resolve_constant_path(constant_path) mod = nesting.find_module_named(owner_name) break if mod end - mod ||= @top_level.find_module_named(owner_name) + mod ||= @file.find_module_named(owner_name) [mod.full_name, path].compact.join('::') if mod end @@ -632,7 +632,7 @@ def find_or_create_constant_owner_name(constant_path) # but RDoc don't track constants of a singleton class of module [(@singleton ? nil : @container), name] elsif const_path.empty? # class ::Foo - [@top_level, name] + [@file, name] else # `class Foo::Bar` or `class ::Foo::Bar` [find_or_create_module_path(const_path, :module), name] end @@ -660,7 +660,7 @@ def add_constant(constant_name, rhs_name, start_line, end_line) @container.find_module_named(rhs_name) end if mod && constant.document_self - a = @container.add_module_alias(mod, rhs_name, constant, @top_level) + a = @container.add_module_alias(mod, rhs_name, constant, @file) a.store = @store a.line = start_line record_location(a) @@ -704,14 +704,14 @@ def add_module_or_class(module_name, start_line, end_line, is_class: false, supe record_location(mod) handle_modifier_directive(mod, start_line) handle_modifier_directive(mod, end_line) - mod.add_comment(comment, @top_level) if comment + mod.add_comment(comment, @file) if comment mod end class RDocVisitor < Prism::Visitor # :nodoc: - def initialize(scanner, top_level, store) + def initialize(scanner, file, store) @scanner = scanner - @top_level = top_level + @file = file @store = store end @@ -841,7 +841,7 @@ def visit_singleton_class_node(node) # If a constant_path does not exist, RDoc creates a module mod = @scanner.find_or_create_module_path(expression_name, :module) if expression_name when Prism::SelfNode - mod = @scanner.container if @scanner.container != @top_level + mod = @scanner.container if @scanner.container != @file end expression.accept(self) if mod diff --git a/lib/rdoc/parser/rd.rb b/lib/rdoc/parser/rd.rb index 19e47e549d..a613c3ddca 100644 --- a/lib/rdoc/parser/rd.rb +++ b/lib/rdoc/parser/rd.rb @@ -10,13 +10,13 @@ class RDoc::Parser::RD < RDoc::Parser parse_files_matching(/\.rd(?:\.[^.]+)?$/) ## - # Creates an rd-format TopLevel for the given file. + # Creates an rd-format File for the given file. def scan - comment = RDoc::Comment.new @content, @top_level + comment = RDoc::Comment.new @content, @file comment.format = 'rd' - @top_level.comment = comment + @file.comment = comment end end diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index c9b662c90a..de2aeb8ae7 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -21,7 +21,7 @@ require_relative 'ripper_state_lex' ## -# Extracts code elements from a source file returning a TopLevel object +# Extracts code elements from a source file returning a File object # containing the constituent file elements. # # This file is based on rtags @@ -170,7 +170,7 @@ class RDoc::Parser::Ruby < RDoc::Parser ## # Creates a new Ruby parser. - def initialize(top_level, content, options, stats) + def initialize(file, content, options, stats) super content = handle_tab_width(content) @@ -313,7 +313,7 @@ def create_module_alias(container, constant, rhs_name) # :nodoc: container.find_module_named rhs_name end - container.add_module_alias mod, rhs_name, constant, @top_level + container.add_module_alias mod, rhs_name, constant, @file end ## @@ -354,7 +354,7 @@ def get_class_or_module(container, ignore_constants = false) # class ::A -> A is in the top level if :on_op == name_t[:kind] and '::' == name_t[:text] then # bug name_t = get_tk - container = @top_level + container = @file given_name << '::' end @@ -375,7 +375,7 @@ def get_class_or_module(container, ignore_constants = false) else c = prev_container.add_module RDoc::NormalModule, name_t[:text] c.ignore unless prev_container.document_children - @top_level.add_to_classes_or_modules c + @file.add_to_classes_or_modules c c end @@ -700,7 +700,7 @@ def make_message(message) # Creates a comment with the correct format def new_comment(comment, line_no = nil) - c = RDoc::Comment.new comment, @top_level, :ruby + c = RDoc::Comment.new comment, @file, :ruby c.line = line_no c.format = @markup c @@ -890,7 +890,7 @@ def parse_class_regular(container, declaration_context, single, # :nodoc: superclass = '::Object' if given_name =~ /^::/ then - declaration_context = @top_level + declaration_context = @file given_name = $' end @@ -909,9 +909,9 @@ def parse_class_regular(container, declaration_context, single, # :nodoc: read_documentation_modifiers cls, RDoc::CLASS_MODIFIERS record_location cls - cls.add_comment comment, @top_level + cls.add_comment comment, @file - @top_level.add_to_classes_or_modules cls + @file.add_to_classes_or_modules cls @stats.add_class cls suppress_parents container, declaration_context unless cls.document_self @@ -931,7 +931,7 @@ def parse_class_singleton(container, name, comment) # :nodoc: unless other then if name =~ /^::/ then name = $' - container = @top_level + container = @file end other = container.add_module RDoc::NormalModule, name @@ -940,7 +940,7 @@ def parse_class_singleton(container, name, comment) # :nodoc: # class << $gvar other.ignore if name.empty? - other.add_comment comment, @top_level + other.add_comment comment, @file end # notify :nodoc: all if not a constant-named class/module @@ -951,7 +951,7 @@ def parse_class_singleton(container, name, comment) # :nodoc: other.clear_comment end - @top_level.add_to_classes_or_modules other + @file.add_to_classes_or_modules other @stats.add_class other read_documentation_modifiers other, RDoc::CLASS_MODIFIERS @@ -1007,7 +1007,7 @@ def parse_constant(container, tk, comment, ignore_constants = false) new_modules.each do |prev_c, new_module| prev_c.add_module_by_normal_module new_module new_module.ignore unless prev_c.document_children - @top_level.add_to_classes_or_modules new_module + @file.add_to_classes_or_modules new_module end end @@ -1140,7 +1140,7 @@ def parse_comment_ghost(container, text, name, column, line_no, # :nodoc: meth.start_collecting_tokens(:ruby) indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column) position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment) - position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}" + position_comment[:text] = "# File #{@file.relative_name}, line #{line_no}" newline = RDoc::Parser::RipperStateLex::Token.new(0, 0, :on_nl, "\n") meth.add_tokens [position_comment, newline, indent] @@ -1183,7 +1183,7 @@ def parse_comment_tomdoc(container, tk, comment) meth.start_collecting_tokens(:ruby) indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column) position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment) - position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}" + position_comment[:text] = "# File #{@file.relative_name}, line #{line_no}" newline = RDoc::Parser::RipperStateLex::Token.new(0, 0, :on_nl, "\n") meth.add_tokens [position_comment, newline, indent] @@ -1366,7 +1366,7 @@ def parse_meta_method(container, single, tk, comment) meth.start_collecting_tokens(:ruby) indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column) position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment) - position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}" + position_comment[:text] = "# File #{@file.relative_name}, line #{line_no}" newline = RDoc::Parser::RipperStateLex::Token.new(0, 0, :on_nl, "\n") meth.add_tokens [position_comment, newline, indent] meth.add_tokens @token_stream @@ -1474,7 +1474,7 @@ def parse_method(container, single, tk, comment) meth.start_collecting_tokens(:ruby) indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column) token = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment) - token[:text] = "# File #{@top_level.relative_name}, line #{line_no}" + token[:text] = "# File #{@file.relative_name}, line #{line_no}" newline = RDoc::Parser::RipperStateLex::Token.new(0, 0, :on_nl, "\n") meth.add_tokens [token, newline, indent] meth.add_tokens @token_stream @@ -1610,7 +1610,7 @@ def parse_method_name_singleton(container, name_t) # :nodoc: elsif (:on_kw == name_t[:kind]) && ('true' == name_t[:text] || 'false' == name_t[:text] || 'nil' == name_t[:text]) then klass_name = "#{name_t[:text].capitalize}Class" container = @store.find_class_named klass_name - container ||= @top_level.add_class RDoc::NormalClass, klass_name + container ||= @file.add_class RDoc::NormalClass, klass_name name = name_t2[:text] else @@ -1719,7 +1719,7 @@ def parse_module(container, single, tk, comment) record_location mod read_documentation_modifiers mod, RDoc::CLASS_MODIFIERS - mod.add_comment comment, @top_level + mod.add_comment comment, @file parse_statements mod # after end modifiers @@ -1743,7 +1743,7 @@ def parse_require(context, comment) name = tk[:text][1..-2] if :on_tstring == tk[:kind] if name then - @top_level.add_require RDoc::Require.new(name, comment) + @file.add_require RDoc::Require.new(name, comment) else unget_tk tk end @@ -1852,7 +1852,7 @@ def parse_statements(container, single = NORMAL, current_method = nil, look_for_directives_in container, comment if container.done_documenting then - throw :eof if RDoc::TopLevel === container + throw :eof if RDoc::File === container container.ongoing_visibility = save_visibility end end @@ -2197,10 +2197,10 @@ def read_documentation_modifiers(context, allowed) def record_location(container) # :nodoc: case container when RDoc::ClassModule then - @top_level.add_to_classes_or_modules container + @file.add_to_classes_or_modules container end - container.record_location @top_level + container.record_location @file end ## @@ -2211,7 +2211,7 @@ def scan catch :eof do begin - parse_top_level_statements @top_level + parse_top_level_statements @file rescue StandardError => e if @content.include?('<%') and @content.include?('%>') then @@ -2247,7 +2247,7 @@ def scan end end - @top_level + @file end ## diff --git a/lib/rdoc/parser/simple.rb b/lib/rdoc/parser/simple.rb index a0edca1b33..9579b79d45 100644 --- a/lib/rdoc/parser/simple.rb +++ b/lib/rdoc/parser/simple.rb @@ -14,25 +14,25 @@ class RDoc::Parser::Simple < RDoc::Parser ## # Prepare to parse a plain file - def initialize(top_level, content, options, stats) + def initialize(file, content, options, stats) super preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include content = RDoc::Text.expand_tabs(@content) - @content, = preprocess.run_pre_processes(content, @top_level, 1, :simple) + @content, = preprocess.run_pre_processes(content, @file, 1, :simple) end ## - # Extract the file contents and attach them to the TopLevel as a comment + # Extract the file contents and attach them to the File as a comment def scan content = remove_coding_comment @content - comment = RDoc::Comment.new content, @top_level + comment = RDoc::Comment.new content, @file - @top_level.comment = comment - @top_level + @file.comment = comment + @file end ## diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb index 8beeac52f5..af958f2e58 100644 --- a/lib/rdoc/rdoc.rb +++ b/lib/rdoc/rdoc.rb @@ -174,11 +174,11 @@ def setup_output_dir(dir, force) if @options.dry_run then # do nothing - elsif File.exist? dir then - error "#{dir} exists and is not a directory" unless File.directory? dir + elsif ::File.exist? dir then + error "#{dir} exists and is not a directory" unless ::File.directory? dir begin - File.open flag_file do |io| + ::File.open flag_file do |io| unless force then Time.parse io.gets @@ -217,7 +217,7 @@ def update_output_dir(op_dir, time, last = {}) time = Time.at(ENV['SOURCE_DATE_EPOCH'].to_i).gmtime end - File.open output_flag_file(op_dir), "w" do |f| + ::File.open output_flag_file(op_dir), "w" do |f| f.puts time.rfc2822 last.each do |n, t| f.puts "#{n}\t#{t.rfc2822}" @@ -229,7 +229,7 @@ def update_output_dir(op_dir, time, last = {}) # Return the path name of the flag file in an output directory. def output_flag_file(op_dir) - File.join op_dir, "created.rid" + ::File.join op_dir, "created.rid" end ## @@ -239,12 +239,12 @@ def output_flag_file(op_dir) def parse_dot_doc_file(in_dir, filename) # read and strip comments - patterns = File.read(filename).gsub(/#.*/, '') + patterns = ::File.read(filename).gsub(/#.*/, '') result = {} patterns.split(' ').each do |patt| - candidates = Dir.glob(File.join(in_dir, patt)) + candidates = Dir.glob(::File.join(in_dir, patt)) result.update normalized_file_list(candidates, false, @options.exclude) end @@ -271,7 +271,7 @@ def normalized_file_list(relative_files, force_doc = false, rel_file_name = rel_file_name.sub(/^\.\//, '') next if rel_file_name.end_with? 'created.rid' next if exclude_pattern && exclude_pattern =~ rel_file_name - stat = File.stat rel_file_name rescue next + stat = ::File.stat rel_file_name rescue next case type = stat.ftype when "file" then @@ -284,15 +284,15 @@ def normalized_file_list(relative_files, force_doc = false, when "directory" then next if UNCONDITIONALLY_SKIPPED_DIRECTORIES.include?(rel_file_name) - basename = File.basename(rel_file_name) + basename = ::File.basename(rel_file_name) next if options.skip_tests && TEST_SUITE_DIRECTORY_NAMES.include?(basename) - created_rid = File.join rel_file_name, "created.rid" - next if File.file? created_rid + created_rid = ::File.join rel_file_name, "created.rid" + next if ::File.file? created_rid - dot_doc = File.join rel_file_name, RDoc::DOT_DOC_FILENAME + dot_doc = ::File.join rel_file_name, RDoc::DOT_DOC_FILENAME - if File.file? dot_doc then + if ::File.file? dot_doc then file_list.update(parse_dot_doc_file(rel_file_name, dot_doc)) else file_list.update(list_files_in_directory(rel_file_name)) @@ -312,13 +312,13 @@ def normalized_file_list(relative_files, force_doc = false, # for .document files. def list_files_in_directory(dir) - files = Dir.glob File.join(dir, "*") + files = Dir.glob ::File.join(dir, "*") normalized_file_list files, false, @options.exclude end ## - # Parses +filename+ and returns an RDoc::TopLevel + # Parses +filename+ and returns an RDoc::File def parse_file(filename) encoding = @options.encoding @@ -345,20 +345,20 @@ def parse_file(filename) relative_path.relative_path_from @options.page_dir end - top_level = @store.add_file filename, relative_name: relative_path.to_s + file = @store.add_file filename, relative_name: relative_path.to_s - parser = RDoc::Parser.for top_level, content, @options, @stats + parser = RDoc::Parser.for file, content, @options, @stats return unless parser parser.scan # restart documentation for the classes & modules found - top_level.classes_or_modules.each do |cm| + file.classes_or_modules.each do |cm| cm.done_documenting = false end - top_level + file rescue Errno::EACCES => e $stderr.puts <<-EOF @@ -422,7 +422,7 @@ def remove_unparseable(files) files.reject do |file, *| file =~ /\.(?:class|eps|erb|scpt\.txt|svg|ttf|yml)$/i or (file =~ /tags$/i and - /\A(\f\n[^,]+,\d+$|!_TAG_)/.match?(File.binread(file, 100))) + /\A(\f\n[^,]+,\d+$|!_TAG_)/.match?(::File.binread(file, 100))) end end diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb index 13ad9366ec..637a774f73 100644 --- a/lib/rdoc/ri/driver.rb +++ b/lib/rdoc/ri/driver.rb @@ -99,7 +99,7 @@ def self.default_options def self.dump(data_path) require 'pp' - File.open data_path, 'rb' do |io| + ::File.open data_path, 'rb' do |io| pp Marshal.load(io.read) end end @@ -111,7 +111,7 @@ def self.process_args(argv) options = default_options opts = OptionParser.new do |opt| - opt.program_name = File.basename $0 + opt.program_name = ::File.basename $0 opt.version = RDoc::VERSION opt.release = nil opt.summary_indent = ' ' * 4 @@ -148,7 +148,7 @@ def self.process_args(argv) #{opt.program_name} Fil #{opt.program_name} File - #{opt.program_name} File.new + #{opt.program_name} ::File.new #{opt.program_name} zip #{opt.program_name} rdoc:README #{opt.program_name} ruby:comments @@ -283,11 +283,11 @@ def self.process_args(argv) "documentation in addition to the standard", "directories. May be repeated.") do |value| value.each do |dir| - unless File.directory? dir then + unless ::File.directory? dir then raise OptionParser::InvalidArgument, "#{dir} is not a directory" end - options[:extra_doc_dirs] << File.expand_path(dir) + options[:extra_doc_dirs] << ::File.expand_path(dir) end end @@ -350,15 +350,15 @@ def self.process_args(argv) opt.on("--dump=CACHE", "Dump data from an ri cache or data file.") do |value| - unless File.readable?(value) + unless ::File.readable?(value) abort "#{value.inspect} is not readable" end - if File.directory?(value) + if ::File.directory?(value) abort "#{value.inspect} is a directory" end - options[:dump_path] = File.new(value) + options[:dump_path] = ::File.new(value) end end diff --git a/lib/rdoc/ri/paths.rb b/lib/rdoc/ri/paths.rb index 8d33c5b7e5..872608025f 100644 --- a/lib/rdoc/ri/paths.rb +++ b/lib/rdoc/ri/paths.rb @@ -12,7 +12,7 @@ module RDoc::RI::Paths version = RbConfig::CONFIG['ruby_version'] - BASE = File.join RbConfig::CONFIG['ridir'], version + BASE = ::File.join RbConfig::CONFIG['ridir'], version HOMEDIR = RDoc.home #:startdoc: @@ -57,7 +57,7 @@ def self.gem_dir(name, version) spec = Gem::Specification.find_by_name name, req - File.join spec.doc_dir, 'ri' + ::File.join spec.doc_dir, 'ri' end ## @@ -71,7 +71,7 @@ def self.gemdirs(filter = :latest) ri_paths = {} all = Gem::Specification.map do |spec| - [File.join(spec.doc_dir, 'ri'), spec.name, spec.version] + [::File.join(spec.doc_dir, 'ri'), spec.name, spec.version] end if filter == :all then @@ -93,7 +93,7 @@ def self.gemdirs(filter = :latest) end all.each do |dir, name, ver| - next unless File.exist? dir + next unless ::File.exist? dir if ri_paths[name].nil? or ver > ri_paths[name].first then ri_paths[name] = [ver, name, dir] @@ -125,7 +125,7 @@ def self.home_dir def self.path(system = true, site = true, home = true, gems = :latest, *extra_dirs) path = raw_path system, site, home, gems, *extra_dirs - path.select { |directory| File.directory? directory } + path.select { |directory| ::File.directory? directory } end ## @@ -152,7 +152,7 @@ def self.raw_path(system, site, home, gems, *extra_dirs) # modern Ruby installations. def self.site_dir - File.join BASE, 'site' + ::File.join BASE, 'site' end ## @@ -165,7 +165,7 @@ def self.site_dir # rdoc-data gem to install system ri data for common versions of Ruby. def self.system_dir - File.join BASE, 'system' + ::File.join BASE, 'system' end end diff --git a/lib/rdoc/rubygems_hook.rb b/lib/rdoc/rubygems_hook.rb index 448afc9a2f..5e2f9436c9 100644 --- a/lib/rdoc/rubygems_hook.rb +++ b/lib/rdoc/rubygems_hook.rb @@ -200,10 +200,10 @@ def generate end document 'ri', options, @ri_dir if - @generate_ri and (@force or not File.exist? @ri_dir) + @generate_ri and (@force or not ::File.exist? @ri_dir) document 'aliki', options, @rdoc_dir if - @generate_rdoc and (@force or not File.exist? @rdoc_dir) + @generate_rdoc and (@force or not ::File.exist? @rdoc_dir) end ## @@ -218,7 +218,7 @@ def new_rdoc # :nodoc: # Is rdoc documentation installed? def rdoc_installed? - File.exist? @rdoc_dir + ::File.exist? @rdoc_dir end ## @@ -227,7 +227,7 @@ def rdoc_installed? def remove base_dir = @spec.base_dir - raise Gem::FilePermissionError, base_dir unless File.writable? base_dir + raise Gem::FilePermissionError, base_dir unless ::File.writable? base_dir FileUtils.rm_rf @rdoc_dir FileUtils.rm_rf @ri_dir @@ -237,7 +237,7 @@ def remove # Is ri data installed? def ri_installed? - File.exist? @ri_dir + ::File.exist? @ri_dir end ## @@ -247,9 +247,9 @@ def setup self.class.load_rdoc raise Gem::FilePermissionError, @doc_dir if - File.exist?(@doc_dir) and not File.writable?(@doc_dir) + ::File.exist?(@doc_dir) and not ::File.writable?(@doc_dir) - FileUtils.mkdir_p @doc_dir unless File.exist? @doc_dir + FileUtils.mkdir_p @doc_dir unless ::File.exist? @doc_dir end end @@ -271,7 +271,7 @@ class RubygemsHook attr_accessor :generate_rdoc, :generate_ri, :force def self.default_gem? - !File.exist?(File.join(__dir__, "..", "rubygems_plugin.rb")) + !::File.exist?(::File.join(__dir__, "..", "rubygems_plugin.rb")) end def initialize(spec, generate_rdoc = false, generate_ri = true) diff --git a/lib/rdoc/servlet.rb b/lib/rdoc/servlet.rb index fbb5bb0258..968e6e5e60 100644 --- a/lib/rdoc/servlet.rb +++ b/lib/rdoc/servlet.rb @@ -81,8 +81,8 @@ def initialize(server, stores, cache, mount_path = nil, extra_doc_dirs = []) # HACK dup $LOAD_PATH.each do |path| - darkfish_dir = File.join path, 'rdoc/generator/template/darkfish/' - next unless File.directory? darkfish_dir + darkfish_dir = ::File.join path, 'rdoc/generator/template/darkfish/' + next unless ::File.directory? darkfish_dir @options.template_dir = darkfish_dir break end @@ -90,7 +90,7 @@ def initialize(server, stores, cache, mount_path = nil, extra_doc_dirs = []) @asset_dirs = { :darkfish => darkfish_dir, :json_index => - File.expand_path('../generator/template/json_index/', __FILE__), + ::File.expand_path('../generator/template/json_index/', __FILE__), } end @@ -100,11 +100,11 @@ def initialize(server, stores, cache, mount_path = nil, extra_doc_dirs = []) def asset(generator_name, req, res) asset_dir = @asset_dirs[generator_name] - asset_path = File.join asset_dir, req.path + asset_path = ::File.join asset_dir, req.path if_modified_since req, res, asset_path - res.body = File.read asset_path + res.body = ::File.read asset_path res.content_type = case req.path when /\.css\z/ then 'text/css' @@ -266,7 +266,7 @@ def generator_for(store) # file has been modified a Last-Modified header is added to +res+. def if_modified_since(req, res, path = nil) - last_modified = File.stat(path).mtime if path + last_modified = ::File.stat(path).mtime if path res['last-modified'] = last_modified.httpdate @@ -292,7 +292,7 @@ def installed_docs extra_counter = 0 ri_paths.map do |path, type| store = RDoc::Store.new(@options, path: path, type: type) - exists = File.exist? store.cache_path + exists = ::File.exist? store.cache_path case type when :gem then @@ -441,7 +441,7 @@ def store_for(source_name) store = RDoc::Store.new(@options, path: ri_dir, type: type) - return store if File.exist? store.cache_path + return store if ::File.exist? store.cache_path raise WEBrick::HTTPStatus::NotFound, "Could not find documentation for \"#{ERB::Util.html_escape(source_name)}\". Please run `gem rdoc --ri gem_name`" diff --git a/lib/rdoc/store.rb b/lib/rdoc/store.rb index 57429e6aad..c93df12f3d 100644 --- a/lib/rdoc/store.rb +++ b/lib/rdoc/store.rb @@ -170,7 +170,7 @@ def add_c_enclosure(variable, namespace) # Adds C variables from an RDoc::Parser::C def add_c_variables(c_parser) - filename = c_parser.top_level.relative_name + filename = c_parser.file.relative_name @c_class_variables[filename] = make_variable_map c_parser.classes @@ -178,19 +178,19 @@ def add_c_variables(c_parser) end ## - # Adds the file with +name+ as an RDoc::TopLevel to the store. Returns the - # created RDoc::TopLevel. + # Adds the file with +name+ as an RDoc::File to the store. Returns the + # created RDoc::File. def add_file(absolute_name, relative_name: absolute_name, parser: nil) - unless top_level = @files_hash[relative_name] then - top_level = RDoc::TopLevel.new absolute_name, relative_name - top_level.parser = parser if parser - top_level.store = self - @files_hash[relative_name] = top_level - @text_files_hash[relative_name] = top_level if top_level.text? + unless file = @files_hash[relative_name] then + file = RDoc::File.new absolute_name, relative_name + file.parser = parser if parser + file.store = self + @files_hash[relative_name] = file + @text_files_hash[relative_name] = file if file.text? end - top_level + file end ## @@ -209,8 +209,8 @@ def resolve_c_superclasses # Sets the parser of +absolute_name+, unless it from a source code file. def update_parser_of_file(absolute_name, parser) - if top_level = @files_hash[absolute_name] then - @text_files_hash[absolute_name] = top_level if top_level.text? + if file = @files_hash[absolute_name] then + @text_files_hash[absolute_name] = file if file.text? end end @@ -262,7 +262,7 @@ def attributes # Path to the cache file def cache_path - File.join @path, 'cache.ri' + ::File.join @path, 'cache.ri' end ## @@ -270,7 +270,7 @@ def cache_path def class_file(klass_name) name = klass_name.split('::').last - File.join class_path(klass_name), "cdesc-#{name}.ri" + ::File.join class_path(klass_name), "cdesc-#{name}.ri" end ## @@ -285,7 +285,7 @@ def class_methods # Path where data for +klass_name+ will be stored (methods or class data) def class_path(klass_name) - File.join @path, *klass_name.split('::') + ::File.join @path, *klass_name.split('::') end ## @@ -409,7 +409,7 @@ def find_class_named(name) def find_class_named_from(name, from) from = find_class_named from unless RDoc::Context === from - until RDoc::TopLevel === from do + until RDoc::File === from do return nil unless from klass = from.find_class_named name @@ -444,7 +444,7 @@ def find_module_named(name) end ## - # Returns the RDoc::TopLevel that is a text file and has the given + # Returns the RDoc::File that is a text file and has the given # +file_name+ def find_text_page(file_name) @@ -491,8 +491,8 @@ def fix_basic_object_inheritance def friendly_path case type when :gem then - parent = File.expand_path '..', @path - "gem #{File.basename parent}" + parent = ::File.expand_path '..', @path + "gem #{::File.basename parent}" when :home then RDoc.home when :site then 'ruby site' when :system then 'ruby core' @@ -701,7 +701,7 @@ def method_file(klass_name, method_name) method_name = $1 if $1 method_name = method_name.gsub(/\W/) { "%%%02x" % $&[0].ord } - File.join class_path(klass_name), "#{method_name}-#{method_type}.ri" + ::File.join class_path(klass_name), "#{method_name}-#{method_type}.ri" end ## @@ -720,7 +720,7 @@ def modules_hash end ## - # Returns the RDoc::TopLevel that is a file and has the given +name+ + # Returns the RDoc::File that is a file and has the given +name+ def page(name) @files_hash.each_value.find do |file| @@ -732,9 +732,9 @@ def page(name) # Path to the ri data for +page_name+ def page_file(page_name) - file_name = File.basename(page_name).gsub('.', '_') + file_name = ::File.basename(page_name).gsub('.', '_') - File.join @path, File.dirname(page_name), "page-#{file_name}.ri" + ::File.join @path, ::File.dirname(page_name), "page-#{file_name}.ri" end ## @@ -796,7 +796,7 @@ def save_cache return if @dry_run - File.open cache_path, 'wb' do |io| + ::File.open cache_path, 'wb' do |io| Marshal.dump @cache, io end end @@ -870,7 +870,7 @@ def save_class(klass) FileUtils.rm_f to_delete - File.open path, 'wb' do |io| + ::File.open path, 'wb' do |io| Marshal.dump klass, io end end @@ -893,7 +893,7 @@ def save_method(klass, method) return if @dry_run - File.open method_file(full_name, method.full_name), 'wb' do |io| + ::File.open method_file(full_name, method.full_name), 'wb' do |io| Marshal.dump method, io end end @@ -906,14 +906,14 @@ def save_page(page) path = page_file page.full_name - FileUtils.mkdir_p File.dirname(path) unless @dry_run + FileUtils.mkdir_p ::File.dirname(path) unless @dry_run cache[:pages] ||= [] cache[:pages] << page.full_name return if @dry_run - File.open path, 'wb' do |io| + ::File.open path, 'wb' do |io| Marshal.dump page, io end end @@ -929,7 +929,7 @@ def save_page(page) def source case type - when :gem then File.basename File.expand_path '..', @path + when :gem then ::File.basename ::File.expand_path '..', @path when :home then 'home' when :site then 'site' when :system then 'ruby' @@ -979,7 +979,7 @@ def unique_modules private def marshal_load(file) - File.open(file, 'rb') {|io| Marshal.load(io, MarshalFilter)} + ::File.open(file, 'rb') {|io| Marshal.load(io, MarshalFilter)} end MarshalFilter = proc do |obj| diff --git a/test/rdoc/code_object/any_method_test.rb b/test/rdoc/code_object/any_method_test.rb index 43dc679d95..7be97aab47 100644 --- a/test/rdoc/code_object/any_method_test.rb +++ b/test/rdoc/code_object/any_method_test.rb @@ -103,8 +103,8 @@ def test_is_alias_for def test_call_seq_handles_aliases # see 0ead786 @store.path = Dir.tmpdir - top_level = @store.add_file 'file.rb' - cm = top_level.add_class RDoc::ClassModule, 'Klass' + file = @store.add_file 'file.rb' + cm = file.add_class RDoc::ClassModule, 'Klass' method_with_call_seq = RDoc::AnyMethod.new(nil, "method_with_call_seq") method_with_call_seq.call_seq = <<~SEQ @@ -128,8 +128,8 @@ def test_call_seq_handles_aliases def test_call_seq_returns_nil_if_alias_is_missing_from_call_seq @store.path = Dir.tmpdir - top_level = @store.add_file 'file.rb' - cm = top_level.add_class RDoc::ClassModule, 'Klass' + file = @store.add_file 'file.rb' + cm = file.add_class RDoc::ClassModule, 'Klass' method_with_call_seq = RDoc::AnyMethod.new(nil, "method_with_call_seq") method_with_call_seq.call_seq = <<~SEQ @@ -203,16 +203,16 @@ def test_markup_code_with_variable_expansion def test_marshal_dump @store.path = Dir.tmpdir - top_level = @store.add_file 'file.rb' + file = @store.add_file 'file.rb' m = RDoc::AnyMethod.new nil, 'method' m.block_params = 'some_block' m.call_seq = 'call_seq' m.comment = 'this is a comment' m.params = 'param' - m.record_location top_level + m.record_location file - cm = top_level.add_class RDoc::ClassModule, 'Klass' + cm = file.add_class RDoc::ClassModule, 'Klass' cm.add_method m section = cm.sections.first @@ -232,7 +232,7 @@ def test_marshal_dump assert_equal 'some_block', loaded.block_params assert_equal 'call_seq', loaded.call_seq assert_equal document, loaded.comment.parse - assert_equal top_level, loaded.file + assert_equal file, loaded.file assert_equal 'Klass#method', loaded.full_name assert_equal 'method', loaded.name assert_equal 'param', loaded.params @@ -287,11 +287,11 @@ def test_marshal_load_instance_method def test_marshal_load_version_0 @store.path = Dir.tmpdir - top_level = @store.add_file 'file.rb' + file = @store.add_file 'file.rb' m = RDoc::AnyMethod.new nil, 'method' - cm = top_level.add_class RDoc::ClassModule, 'Klass' + cm = file.add_class RDoc::ClassModule, 'Klass' cm.add_method m section = cm.sections.first @@ -335,16 +335,16 @@ def test_marshal_load_version_0 def test_marshal_dump_version_2 @store.path = Dir.tmpdir - top_level = @store.add_file 'file.rb' + file = @store.add_file 'file.rb' m = RDoc::AnyMethod.new nil, 'method' m.block_params = 'some_block' m.call_seq = 'call_seq' m.comment = 'this is a comment' m.params = 'param' - m.record_location top_level + m.record_location file - cm = top_level.add_class RDoc::ClassModule, 'Klass' + cm = file.add_class RDoc::ClassModule, 'Klass' cm.add_method m section = cm.sections.first @@ -376,7 +376,7 @@ def test_marshal_dump_version_2 assert_equal 'some_block', loaded.block_params assert_equal 'call_seq', loaded.call_seq assert_equal document, loaded.comment.parse - assert_equal top_level, loaded.file + assert_equal file, loaded.file assert_equal 'Klass#method', loaded.full_name assert_equal 'method', loaded.name assert_equal 'param', loaded.params diff --git a/test/rdoc/code_object/class_module_test.rb b/test/rdoc/code_object/class_module_test.rb index 0a552d1fb4..5ef9a019b3 100644 --- a/test/rdoc/code_object/class_module_test.rb +++ b/test/rdoc/code_object/class_module_test.rb @@ -9,19 +9,19 @@ def test_add_comment tl3 = @store.add_file 'three.rb' cm = RDoc::ClassModule.new 'Klass' - comment_tl1 = RDoc::Comment.new('# comment 1', @top_level, :ruby) + comment_tl1 = RDoc::Comment.new('# comment 1', @file, :ruby) cm.add_comment comment_tl1, tl1 assert_equal [[comment_tl1, tl1]], cm.comment_location assert_equal 'comment 1', cm.comment.text - comment_tl2 = RDoc::Comment.new('# comment 2', @top_level, :ruby) + comment_tl2 = RDoc::Comment.new('# comment 2', @file, :ruby) cm.add_comment comment_tl2, tl2 assert_equal [[comment_tl1, tl1], [comment_tl2, tl2]], cm.comment_location assert_equal "comment 1\n---\ncomment 2", cm.comment - comment_tl3 = RDoc::Comment.new('# * comment 3', @top_level, :ruby) + comment_tl3 = RDoc::Comment.new('# * comment 3', @file, :ruby) cm.add_comment comment_tl3, tl3 assert_equal [[comment_tl1, tl1], @@ -33,7 +33,7 @@ def test_add_comment def test_add_comment_comment cm = RDoc::ClassModule.new 'Klass' - cm.add_comment comment('comment'), @top_level + cm.add_comment comment('comment'), @file assert_equal 'comment', cm.comment.text end @@ -42,8 +42,8 @@ def test_add_comment_duplicate tl1 = @store.add_file 'one.rb' cm = RDoc::ClassModule.new 'Klass' - comment1 = RDoc::Comment.new('# comment 1', @top_level, :ruby) - comment2 = RDoc::Comment.new('# comment 2', @top_level, :ruby) + comment1 = RDoc::Comment.new('# comment 1', @file, :ruby) + comment2 = RDoc::Comment.new('# comment 2', @file, :ruby) cm.add_comment comment1, tl1 cm.add_comment comment2, tl1 @@ -68,15 +68,15 @@ def test_ancestors def test_comment_equals cm = RDoc::ClassModule.new 'Klass' - cm.comment = RDoc::Comment.new('# comment 1', @top_level, :ruby) + cm.comment = RDoc::Comment.new('# comment 1', @file, :ruby) assert_equal 'comment 1', cm.comment.to_s - cm.comment = RDoc::Comment.new('# comment 2', @top_level, :ruby) + cm.comment = RDoc::Comment.new('# comment 2', @file, :ruby) assert_equal "comment 1\n---\ncomment 2", cm.comment.to_s - cm.comment = RDoc::Comment.new('# * comment 3', @top_level, :ruby) + cm.comment = RDoc::Comment.new('# * comment 3', @file, :ruby) assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment.to_s end @@ -111,11 +111,11 @@ def test_documented_eh refute cm.documented?, 'no comments, no markers' - cm.add_comment '', @top_level + cm.add_comment '', @file refute cm.documented?, 'empty comment' - cm.add_comment 'hi', @top_level + cm.add_comment 'hi', @file assert cm.documented?, 'commented' @@ -135,7 +135,7 @@ def test_each_ancestor def test_each_ancestor_cycle m_incl = RDoc::Include.new 'M', nil - m = @top_level.add_module RDoc::NormalModule, 'M' + m = @file.add_module RDoc::NormalModule, 'M' m.add_include m_incl assert_empty m.each_ancestor.to_a @@ -1185,7 +1185,7 @@ def test_parse_comment_location end def test_remove_nodoc_children - parent = @top_level.add_class RDoc::ClassModule, 'A' + parent = @file.add_class RDoc::ClassModule, 'A' parent.modules_hash.replace 'B' => true, 'C' => true @store.modules_hash.replace 'A::B' => true @@ -1384,17 +1384,17 @@ def test_update_aliases_reparent def test_update_aliases_reparent_root store = RDoc::Store.new(RDoc::Options.new) - top_level = store.add_file 'file.rb' + file = store.add_file 'file.rb' - klass = top_level.add_class RDoc::NormalClass, 'Klass' - object = top_level.add_class RDoc::NormalClass, 'Object' + klass = file.add_class RDoc::NormalClass, 'Klass' + object = file.add_class RDoc::NormalClass, 'Object' const = RDoc::Constant.new 'A', nil, '' - const.record_location top_level + const.record_location file const.is_alias_for = klass a = RDoc::Constant.new 'A', '', '' - top_level.add_module_alias klass, klass.name, a, top_level + file.add_module_alias klass, klass.name, a, file object.add_constant const diff --git a/test/rdoc/code_object/constant_test.rb b/test/rdoc/code_object/constant_test.rb index 52e40da138..41ffddc98c 100644 --- a/test/rdoc/code_object/constant_test.rb +++ b/test/rdoc/code_object/constant_test.rb @@ -10,10 +10,10 @@ def setup end def test_documented_eh - top_level = @store.add_file 'file.rb' + file = @store.add_file 'file.rb' const = RDoc::Constant.new 'CONST', nil, nil - top_level.add_constant const + file.add_constant const refute const.documented? @@ -23,10 +23,10 @@ def test_documented_eh end def test_documented_eh_alias - top_level = @store.add_file 'file.rb' + file = @store.add_file 'file.rb' const = RDoc::Constant.new 'CONST', nil, nil - top_level.add_constant const + file.add_constant const refute const.documented? @@ -34,7 +34,7 @@ def test_documented_eh_alias refute const.documented? - @c1.add_comment comment('comment'), @top_level + @c1.add_comment comment('comment'), @file assert const.documented? end @@ -44,10 +44,10 @@ def test_full_name end def test_is_alias_for - top_level = @store.add_file 'file.rb' + file = @store.add_file 'file.rb' c = RDoc::Constant.new 'CONST', nil, 'comment' - top_level.add_constant c + file.add_constant c assert_nil c.is_alias_for @@ -61,15 +61,15 @@ def test_is_alias_for end def test_marshal_dump - top_level = @store.add_file 'file.rb' + file = @store.add_file 'file.rb' c = RDoc::Constant.new 'CONST', nil, 'this is a comment' - c.record_location top_level + c.record_location file - aliased = top_level.add_class RDoc::NormalClass, 'Aliased' + aliased = file.add_class RDoc::NormalClass, 'Aliased' c.is_alias_for = aliased - cm = top_level.add_class RDoc::NormalClass, 'Klass' + cm = file.add_class RDoc::NormalClass, 'Klass' cm.add_constant c section = cm.sections.first @@ -83,7 +83,7 @@ def test_marshal_dump assert_equal aliased, loaded.is_alias_for assert_equal document, loaded.comment.parse - assert_equal top_level, loaded.file + assert_equal file, loaded.file assert_equal 'Klass::CONST', loaded.full_name assert_equal 'CONST', loaded.name assert_equal :public, loaded.visibility @@ -92,12 +92,12 @@ def test_marshal_dump end def test_marshal_load - top_level = @store.add_file 'file.rb' + file = @store.add_file 'file.rb' c = RDoc::Constant.new 'CONST', nil, 'this is a comment' - c.record_location top_level + c.record_location file - cm = top_level.add_class RDoc::NormalClass, 'Klass' + cm = file.add_class RDoc::NormalClass, 'Klass' cm.add_constant c section = cm.sections.first @@ -111,7 +111,7 @@ def test_marshal_load assert_nil loaded.is_alias_for assert_equal document, loaded.comment.parse - assert_equal top_level, loaded.file + assert_equal file, loaded.file assert_equal 'Klass::CONST', loaded.full_name assert_equal 'CONST', loaded.name assert_equal :public, loaded.visibility @@ -122,10 +122,10 @@ def test_marshal_load end def test_marshal_load_version_0 - top_level = @store.add_file 'file.rb' + file = @store.add_file 'file.rb' - aliased = top_level.add_class RDoc::NormalClass, 'Aliased' - cm = top_level.add_class RDoc::NormalClass, 'Klass' + aliased = file.add_class RDoc::NormalClass, 'Aliased' + cm = file.add_class RDoc::NormalClass, 'Klass' section = cm.sections.first loaded = Marshal.load "\x04\bU:\x13RDoc::Constant[\x0Fi\x00I" + @@ -143,7 +143,7 @@ def test_marshal_load_version_0 assert_equal aliased, loaded.is_alias_for assert_equal document, loaded.comment.parse - assert_equal top_level, loaded.file + assert_equal file, loaded.file assert_equal 'Klass::CONST', loaded.full_name assert_equal 'CONST', loaded.name assert_equal :public, loaded.visibility @@ -154,13 +154,13 @@ def test_marshal_load_version_0 end def test_marshal_round_trip - top_level = @store.add_file 'file.rb' + file = @store.add_file 'file.rb' c = RDoc::Constant.new 'CONST', nil, 'this is a comment' - c.record_location top_level + c.record_location file c.is_alias_for = 'Unknown' - cm = top_level.add_class RDoc::NormalClass, 'Klass' + cm = file.add_class RDoc::NormalClass, 'Klass' cm.add_constant c section = cm.sections.first diff --git a/test/rdoc/code_object/include_test.rb b/test/rdoc/code_object/include_test.rb index c49e1824ba..967dec00cb 100644 --- a/test/rdoc/code_object/include_test.rb +++ b/test/rdoc/code_object/include_test.rb @@ -8,7 +8,7 @@ def setup @inc = RDoc::Include.new 'M1', 'comment' @inc.parent = @m1 - @inc.record_location @top_level + @inc.record_location @file @inc.store = @store end @@ -98,11 +98,11 @@ def test_module_extended def test_store_equals incl = RDoc::Include.new 'M', nil - incl.record_location RDoc::TopLevel.new @top_level.name + incl.record_location RDoc::File.new @file.name incl.store = @store - assert_same @top_level, incl.file + assert_same @file, incl.file assert_same @store, incl.file.store end diff --git a/test/rdoc/code_object/method_attr_test.rb b/test/rdoc/code_object/method_attr_test.rb index bffcb799d3..7ee8c7dafc 100644 --- a/test/rdoc/code_object/method_attr_test.rb +++ b/test/rdoc/code_object/method_attr_test.rb @@ -179,14 +179,14 @@ def test_pretty_print temp_dir do |tmpdir| s = RDoc::RI::Store.new(RDoc::Options.new, path: tmpdir) - top_level = s.add_file 'file.rb' + file = s.add_file 'file.rb' meth_bang = RDoc::AnyMethod.new nil, 'method!' - meth_bang.record_location top_level + meth_bang.record_location file meth_bang_alias = RDoc::Alias.new nil, 'method!', 'method_bang', '' - meth_bang_alias.record_location top_level + meth_bang_alias.record_location file - klass = top_level.add_class RDoc::NormalClass, 'Object' + klass = file.add_class RDoc::NormalClass, 'Object' klass.add_method meth_bang meth_bang.add_alias meth_bang_alias, klass diff --git a/test/rdoc/code_object/normal_class_test.rb b/test/rdoc/code_object/normal_class_test.rb index 431ca4b3f1..72aefe385b 100644 --- a/test/rdoc/code_object/normal_class_test.rb +++ b/test/rdoc/code_object/normal_class_test.rb @@ -4,10 +4,10 @@ class RDocNormalClassTest < XrefTestCase def test_ancestors - klass = @top_level.add_class RDoc::NormalClass, 'Klass' + klass = @file.add_class RDoc::NormalClass, 'Klass' incl = RDoc::Include.new 'Incl', '' - sub_klass = @top_level.add_class RDoc::NormalClass, 'SubClass' + sub_klass = @file.add_class RDoc::NormalClass, 'SubClass' sub_klass.superclass = klass sub_klass.add_include incl @@ -15,9 +15,9 @@ def test_ancestors end def test_ancestors_multilevel - c1 = @top_level.add_class RDoc::NormalClass, 'Outer' - c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1.full_name - c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2.full_name + c1 = @file.add_class RDoc::NormalClass, 'Outer' + c2 = @file.add_class RDoc::NormalClass, 'Middle', c1.full_name + c3 = @file.add_class RDoc::NormalClass, 'Inner', c2.full_name assert_equal [c2, c1, @object, 'BasicObject'], c3.ancestors end @@ -30,9 +30,9 @@ def test_aref def test_direct_ancestors incl = RDoc::Include.new 'Incl', '' - c1 = @top_level.add_class RDoc::NormalClass, 'Outer' - c2 = @top_level.add_class RDoc::NormalClass, 'Middle', c1.full_name - c3 = @top_level.add_class RDoc::NormalClass, 'Inner', c2.full_name + c1 = @file.add_class RDoc::NormalClass, 'Outer' + c2 = @file.add_class RDoc::NormalClass, 'Middle', c1.full_name + c3 = @file.add_class RDoc::NormalClass, 'Inner', c2.full_name c3.add_include incl assert_equal [incl.name, c2], c3.direct_ancestors diff --git a/test/rdoc/code_object/normal_module_test.rb b/test/rdoc/code_object/normal_module_test.rb index 0a45b950f6..310f5b8ce3 100644 --- a/test/rdoc/code_object/normal_module_test.rb +++ b/test/rdoc/code_object/normal_module_test.rb @@ -10,15 +10,15 @@ def setup end def test_ancestors_module - top_level = @store.add_file 'file.rb' - mod = top_level.add_module RDoc::NormalModule, 'Mod' + file = @store.add_file 'file.rb' + mod = file.add_module RDoc::NormalModule, 'Mod' incl = RDoc::Include.new 'Incl', '' mod.add_include incl assert_equal [incl.name], mod.ancestors - mod2 = top_level.add_module RDoc::NormalModule, 'Inc2' + mod2 = file.add_module RDoc::NormalModule, 'Inc2' inc2 = RDoc::Include.new 'Inc2', '' mod.add_include inc2 assert_equal [mod2, incl.name], mod.ancestors diff --git a/test/rdoc/generator/aliki/highlight_c_test.rb b/test/rdoc/generator/aliki/highlight_c_test.rb index 4d7a1089db..20d65e7489 100644 --- a/test/rdoc/generator/aliki/highlight_c_test.rb +++ b/test/rdoc/generator/aliki/highlight_c_test.rb @@ -11,13 +11,13 @@ end class RDocGeneratorAlikiHighlightCTest < Test::Unit::TestCase - HIGHLIGHT_C_JS_PATH = File.expand_path( + HIGHLIGHT_C_JS_PATH = ::File.expand_path( '../../../../lib/rdoc/generator/template/aliki/js/c_highlighter.js', __dir__ ) HIGHLIGHT_C_JS = begin - highlight_c_js = File.read(HIGHLIGHT_C_JS_PATH) + highlight_c_js = ::File.read(HIGHLIGHT_C_JS_PATH) # We need to modify the JS slightly to make it work in the context of a test. highlight_c_js.gsub( diff --git a/test/rdoc/generator/aliki_test.rb b/test/rdoc/generator/aliki_test.rb index 8d3ba737c4..9207b78c5b 100644 --- a/test/rdoc/generator/aliki_test.rb +++ b/test/rdoc/generator/aliki_test.rb @@ -12,15 +12,15 @@ def setup @options = RDoc::Options.new @options.option_parser = OptionParser.new - @tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_aliki_#{$$}" + @tmpdir = ::File.join Dir.tmpdir, "test_rdoc_generator_aliki_#{$$}" FileUtils.mkdir_p @tmpdir Dir.chdir @tmpdir @options.op_dir = @tmpdir @options.generator = RDoc::Generator::Aliki $LOAD_PATH.each do |path| - aliki_dir = File.join path, 'rdoc/generator/template/aliki/' - next unless File.directory? aliki_dir + aliki_dir = ::File.join path, 'rdoc/generator/template/aliki/' + next unless ::File.directory? aliki_dir @options.template_dir = aliki_dir break end @@ -30,9 +30,9 @@ def setup @g = @options.generator.new @store, @options @rdoc.generator = @g - @top_level = @store.add_file 'file.rb' - @top_level.parser = RDoc::Parser::Ruby - @klass = @top_level.add_class RDoc::NormalClass, 'Klass' + @file = @store.add_file 'file.rb' + @file.parser = RDoc::Parser::Ruby + @klass = @file.add_class RDoc::NormalClass, 'Klass' @meth = RDoc::AnyMethod.new nil, 'method' @meth_with_html_tag_yield = RDoc::AnyMethod.new nil, 'method_with_html_tag_yield' @@ -68,15 +68,15 @@ def test_write_style_sheet_copies_css_and_js_only assert_file 'js/c_highlighter.js' # Aliki should NOT have fonts (unlike Darkfish) - refute File.exist?('css/fonts.css'), 'Aliki should not copy fonts.css' - refute File.exist?('fonts'), 'Aliki should not copy fonts directory' + refute ::File.exist?('css/fonts.css'), 'Aliki should not copy fonts.css' + refute ::File.exist?('fonts'), 'Aliki should not copy fonts directory' end # Aliki-specific: verify version query strings on asset references def test_asset_version_query_strings @g.generate - content = File.binread('index.html') + content = ::File.binread('index.html') # CSS should have version query string assert_match %r{css/rdoc\.css\?v=#{Regexp.escape(RDoc::VERSION)}}, content @@ -91,7 +91,7 @@ def test_open_graph_meta_tags_for_index @options.title = "My Ruby Project" @g.generate - content = File.binread('index.html') + content = ::File.binread('index.html') assert_match %r{}, content assert_match %r{}, content @@ -99,13 +99,13 @@ def test_open_graph_meta_tags_for_index end def test_open_graph_meta_tags_for_class - top_level = @store.add_file 'file.rb' - top_level.add_class @klass.class, @klass.name - @klass.add_comment "A useful class for doing things.", top_level + file = @store.add_file 'file.rb' + file.add_class @klass.class, @klass.name + @klass.add_comment "A useful class for doing things.", file @g.generate - content = File.binread('Klass.html') + content = ::File.binread('Klass.html') assert_match %r{}, content @@ -116,7 +116,7 @@ def test_twitter_meta_tags_for_index @options.title = "My Ruby Project" @g.generate - content = File.binread('index.html') + content = ::File.binread('index.html') assert_match %r{}, content assert_match %r{}, content @@ -124,27 +124,27 @@ def test_twitter_meta_tags_for_index end def test_twitter_meta_tags_for_class - top_level = @store.add_file 'file.rb' - top_level.add_class @klass.class, @klass.name - @klass.add_comment "A useful class for doing things.", top_level + file = @store.add_file 'file.rb' + file.add_class @klass.class, @klass.name + @klass.add_comment "A useful class for doing things.", file @g.generate - content = File.binread('Klass.html') + content = ::File.binread('Klass.html') assert_match %r{}, content assert_match %r{}, content end def test_meta_tags_multiline_format - top_level = @store.add_file 'file.rb' - top_level.add_class @klass.class, @klass.name + file = @store.add_file 'file.rb' + file.add_class @klass.class, @klass.name inner = @klass.add_class RDoc::NormalClass, 'Inner' - inner.add_comment "This is a normal class.", top_level + inner.add_comment "This is a normal class.", file @g.generate - content = File.binread('Klass/Inner.html') + content = ::File.binread('Klass/Inner.html') # Aliki formats meta tags across multiple lines assert_match %r{name="keywords"\s+content="ruby,class,Klass::Inner"}m, content @@ -153,9 +153,9 @@ def test_meta_tags_multiline_format def test_template_stylesheets_with_version css = Tempfile.create(%W[custom .css], Dir.mktmpdir('tmp', '.')) - File.write(css, '') + ::File.write(css, '') css.close - base = File.basename(css) + base = ::File.basename(css) @options.template_stylesheets << css @@ -163,16 +163,16 @@ def test_template_stylesheets_with_version assert_file base # Aliki includes version in query string for custom stylesheets too - assert_match %r{href="\./#{Regexp.escape(base)}\?v=#{Regexp.escape(RDoc::VERSION)}"}, File.binread('index.html') + assert_match %r{href="\./#{Regexp.escape(base)}\?v=#{Regexp.escape(RDoc::VERSION)}"}, ::File.binread('index.html') end def test_generated_method_with_html_tag_yield_escapes_xss - top_level = @store.add_file 'file.rb' - top_level.add_class @klass.class, @klass.name + file = @store.add_file 'file.rb' + file.add_class @klass.class, @klass.name @g.generate - content = File.binread('Klass.html') + content = ::File.binread('Klass.html') # Script tags in yield params should be escaped assert_match %r{%<<script>alert\("atui"\)</script>>}, content @@ -183,7 +183,7 @@ def test_title_escape_prevents_xss @options.title = '' @g.generate - content = File.binread('index.html') + content = ::File.binread('index.html') # Title should be HTML escaped assert_match %r{<script>alert\("xss"\)</script>}, content @@ -192,7 +192,7 @@ def test_title_escape_prevents_xss def test_generate @klass.add_class RDoc::NormalClass, 'Inner' - @klass.add_comment "Test class documentation", @top_level + @klass.add_comment "Test class documentation", @file @g.generate @@ -207,7 +207,7 @@ def test_generate assert_file 'js/aliki.js' # Verify HTML structure - index = File.binread('index.html') + index = ::File.binread('index.html') assert_match %r{}, index assert_match %r{}, index @@ -219,13 +219,13 @@ def test_canonical_url @store.options.canonical_root = @options.canonical_root = "https://example.com/docs/" @g.generate - index_content = File.binread('index.html') + index_content = ::File.binread('index.html') assert_include index_content, '' # Open Graph should also include canonical URL assert_match %r{}, index_content - inner_content = File.binread('Klass/Inner.html') + inner_content = ::File.binread('Klass/Inner.html') assert_include inner_content, '' end @@ -244,7 +244,7 @@ def test_html_lang_from_locale @options.locale = RDoc::I18n::Locale.new 'ja' @g.generate - content = File.binread('index.html') + content = ::File.binread('index.html') assert_include content, '' end end diff --git a/test/rdoc/generator/darkfish_test.rb b/test/rdoc/generator/darkfish_test.rb index 1f0236ad8f..8bed42d8fc 100644 --- a/test/rdoc/generator/darkfish_test.rb +++ b/test/rdoc/generator/darkfish_test.rb @@ -12,15 +12,15 @@ def setup @options = RDoc::Options.new @options.option_parser = OptionParser.new - @tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_darkfish_#{$$}" + @tmpdir = ::File.join Dir.tmpdir, "test_rdoc_generator_darkfish_#{$$}" FileUtils.mkdir_p @tmpdir Dir.chdir @tmpdir @options.op_dir = @tmpdir @options.generator = RDoc::Generator::Darkfish $LOAD_PATH.each do |path| - darkfish_dir = File.join path, 'rdoc/generator/template/darkfish/' - next unless File.directory? darkfish_dir + darkfish_dir = ::File.join path, 'rdoc/generator/template/darkfish/' + next unless ::File.directory? darkfish_dir @options.template_dir = darkfish_dir break end @@ -30,16 +30,16 @@ def setup @g = @options.generator.new @store, @options @rdoc.generator = @g - @top_level = @store.add_file 'file.rb' - @top_level.parser = RDoc::Parser::Ruby - @klass = @top_level.add_class RDoc::NormalClass, 'Klass' + @file = @store.add_file 'file.rb' + @file.parser = RDoc::Parser::Ruby + @klass = @file.add_class RDoc::NormalClass, 'Klass' @alias_constant = RDoc::Constant.new 'A', nil, '' - @alias_constant.record_location @top_level + @alias_constant.record_location @file - @top_level.add_constant @alias_constant + @file.add_constant @alias_constant - @klass.add_module_alias @klass, @klass.name, @alias_constant, @top_level + @klass.add_module_alias @klass, @klass.name, @alias_constant, @file @meth = RDoc::AnyMethod.new nil, 'method' @meth_bang = RDoc::AnyMethod.new nil, 'method!' @@ -52,7 +52,7 @@ def setup @klass.add_method @meth_with_html_tag_yield @klass.add_attribute @attr - @ignored = @top_level.add_class RDoc::NormalClass, 'Ignored' + @ignored = @file.add_class RDoc::NormalClass, 'Ignored' @ignored.ignore @store.complete :private @@ -70,10 +70,10 @@ def teardown end def test_generate - top_level = @store.add_file 'file.rb' - top_level.add_class @klass.class, @klass.name + file = @store.add_file 'file.rb' + file.add_class @klass.class, @klass.name @klass.add_class RDoc::NormalClass, 'Inner' - @klass.add_comment <<~RDOC, top_level + @klass.add_comment <<~RDOC, file = Heading 1 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod == Heading 1.1 @@ -107,14 +107,14 @@ def test_generate encoding = Regexp.escape Encoding::UTF_8.name - assert_match %r%%, File.binread('index.html') - assert_match %r%%, File.binread('Object.html') + assert_match %r%%, ::File.binread('index.html') + assert_match %r%%, ::File.binread('Object.html') - refute_match(/Ignored/, File.binread('index.html')) - summary = File.binread('index.html')[%r[.*]m] + refute_match(/Ignored/, ::File.binread('index.html')) + summary = ::File.binread('index.html')[%r[.*]m] assert_match(%r[Klass/Inner\.html".*>Inner<], summary) - klass = File.binread('Klass.html') + klass = ::File.binread('Klass.html') klassnav = klass[%r[