Class: ReqWalker
- Inherits:
-
Object
- Object
- ReqWalker
- Defined in:
- lib/kwala/lib/cycle_detector.rb
Constant Summary collapse
- URL =
"/"
- REQUIRE_REG =
/^\s*require\s*\(?\s*[\(\'\"]([\w\-\/\.]+)[\"\'\)]/
Class Method Summary collapse
- .clean_file(file) ⇒ Object
- .clean_files(files) ⇒ Object
- .convert_files_path_to(files, from = "./", to = "") ⇒ Object
- .filter_path(path) ⇒ Object
- .find_file(file) ⇒ Object
- .find_ruby_files(dir) ⇒ Object
- .get_require(line) ⇒ Object
- .get_requires(file) ⇒ Object
Class Method Details
.clean_file(file) ⇒ Object
691 692 693 694 695 696 697 698 699 700 701 702 |
# File 'lib/kwala/lib/cycle_detector.rb', line 691 def self.clean_file(file) # Get rid of any "./a.rb" files as they will make duplicates if m = /^\.\/(.*)/.match(file) file = m[1] end if m = /(.*)?(\.rb|\.so)$/.match(file) m[1] else file end end |
.clean_files(files) ⇒ Object
704 705 706 707 708 709 710 |
# File 'lib/kwala/lib/cycle_detector.rb', line 704 def self.clean_files(files) nfiles = Array.new files.each do |f| nfiles<< clean_file(f) end nfiles end |
.convert_files_path_to(files, from = "./", to = "") ⇒ Object
716 717 718 |
# File 'lib/kwala/lib/cycle_detector.rb', line 716 def self.convert_files_path_to(files, from = "./", to = "") files.map { |f| f.sub(from, to) } end |
.filter_path(path) ⇒ Object
684 685 686 687 688 689 |
# File 'lib/kwala/lib/cycle_detector.rb', line 684 def self.filter_path(path) #path.find_all { |p| p !~ /\/ruby\/1\.8/ } #|| p !~ /\/ruby\/site_ruby\/1\.8/ } #["./"] [] path end |
.find_file(file) ⇒ Object
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 |
# File 'lib/kwala/lib/cycle_detector.rb', line 659 def self.find_file(file) return nil if file =~ /\.so$/ if file !~ /\.rb$/ nfile = file + ".rb" else nfile = file end [file, nfile].uniq.each do |chk| if File.exists?(chk) && !File.directory?(chk) return chk end end filter_path($LOAD_PATH).each do |path| #$LOAD_PATH.each do |path| npath = path + "/" + nfile if File.exists?(npath) && !File.directory?(npath) return npath end end nil end |
.find_ruby_files(dir) ⇒ Object
712 713 714 |
# File 'lib/kwala/lib/cycle_detector.rb', line 712 def self.find_ruby_files(dir) ProjectBuilderUtils.find_ruby_files(dir) end |
.get_require(line) ⇒ Object
651 652 653 654 655 656 657 |
# File 'lib/kwala/lib/cycle_detector.rb', line 651 def self.get_require(line) if m = REQUIRE_REG.match(line) return m[1].split(" ").first.gsub("\"","").gsub("'","") else return nil end end |
.get_requires(file) ⇒ Object
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 |
# File 'lib/kwala/lib/cycle_detector.rb', line 635 def self.get_requires(file) reqs = Array.new path = find_file(file) return reqs if path.nil? IO.readlines(path).each_with_index do |line, idx| # Add this break to ignore requires at the end... break if idx > 150 if r = get_require(line) reqs<< r end end reqs end |