class File
rdep - The Ruby Dependency Tool Version 1.4
Hal E. Fulton 2 November 2002 Ruby's license
Purpose
Determine the library files on which a specified Ruby file is dependent (and their location and availability).
Usage notes
Usage: ruby rdep.rb sourcefile
The sourcefile may or may not have a .rb extension.
The directories in the $: array (which includes the RUBYLIB environment
variable) are searched first. File extensions are currently searched for
in this order: no extension, .rb, .o, .so, .dll (this may not be correct).
If there are no detected dependencies, the program will give the
message, "No dependencies found."
If the program finds [auto]load and require statements that it can
understand, it searches for the specified files. Any recognized Ruby
source files (*.rb) are processed recursively in the same way. No attempt
is made to open the files that appear to be binary.
The program will print up to four lists (any or all may be omitted):
1. A list of files it found by going through RUBYLIB.;
2. A list of files found under the searchroot (or under '.');
3. A list of directories under searchroot which should perhaps be
added to RUBYLIB; and
4. A list of files (without extensions) which could not be found.
If there were unparseable [auto]load or require statements, a warning
will be issued.
Between lists 3 and 4, the program will give an opinion about the overall
situation. The worst case is that files were not found; the uncertain
case is when there were unparseable statements; and the best case is
when all files could be found (lists 1 and 2).
Exit codes
0 - Usage or successful execution 1 - Nonexistent sourcefile specified 2 - Improper sourcefile (pipe, special file, ...) 3 - Some kind of problem reading a file
Limitations
Requires Ruby 1.6.0 or higher
No recursion on binaries
Can't look at dynamically built names
Can't detect "tested" requires (e.g.: flag = require "foo.rb")
[auto]load/require can be preceded only by whitespace on the line
Only recognizes simple strings ("file" or 'file')
Does not recognized named constants (e.g.: require MyFile)
Assumes every directory entry is either a file or subdirectory
Does not handle the Windows variable RUBYLIB_PREFIX
May be SLOW if a directory structure is deep (especially
on Windows with 1.6.x)
Known bugs:
Logic may be incorrect in terms of search order, file extensions, etc. Injected a bug in 1.3: In rare cases will recurse until stack overflow
Revision history
Version 1.0 - 13 October 2000 - Initial release
Version 1.1 - 10 July 2001 - Bug fixes
Version 1.2 - 15 August 2002 - Works correctly on Win98
Version 1.3 - 21 October 2002 - Removed globals; removed search root;
added $: instead of RUBYLIB; etc.
Version 1.4 - 2 November 2002 - Fixed autoload recursion bug
To-do list
Possibly change extension search order? Possibly add extensions to list? Are explicit extensions allowed other than .rb? Is a null extension really legal? Additional tests/safeguards? (file permissions, non-empty files,...) Change inconsistent expansion of tilde, dot, etc.? Make it smarter somehow??
# # #doc_skip - iterator to skip embedded docs in Ruby input file #
Public Instance Methods
doc_skip() { |str| ... }
click to toggle source
# File examples/rdep-rgl.rb, line 121 def doc_skip loop do str = gets break if not str if str =~ /^=begin([ \t]|$)/ loop do str = gets break if not str break if str =~ /^=end([ \t]|$)/ end else yield str end end end