Class/Module Index [+]

Quicksearch

Nanoc::Extra::FilesystemTools

Contains useful functions for managing the filesystem.

@api private

Public Class Methods

all_files_in(dir_name, recursion_limit=10) click to toggle source

Returns all files in the given directory and directories below it, following symlinks up to a maximum of `recursion_limit` times.

@param [String] dir_name The name of the directory whose contents to

fetch

@param [Integer] recursion_limit The maximum number of times to

recurse into a symlink to a directory

@return [Array<String>] A list of filenames

@raise [MaxSymlinkDepthExceededError] if too many indirections are

encountered while resolving symlinks

@raise [UnsupportedFileTypeError] if a file of an unsupported type is

detected (something other than file, directory or link)
# File lib/nanoc/extra/filesystem_tools.rb, line 61
def all_files_in(dir_name, recursion_limit=10)
  Dir[dir_name + '/**/*'].map do |fn|
    case File.ftype(fn)
    when 'link'
      if 0 == recursion_limit
        raise MaxSymlinkDepthExceededError.new(fn)
      else
        absolute_target = self.resolve_symlink(fn)
        if File.file?(absolute_target)
          fn
        else
          all_files_in(absolute_target, recursion_limit-1).map do |sfn|
            fn + sfn[absolute_target.size..-1]
          end
        end
      end
    when 'file'
      fn
    when 'directory'
      nil
    else
      raise UnsupportedFileTypeError.new(fn)
    end
  end.compact.flatten
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.