Class: StrangeRequiresDetector
- Inherits:
-
Object
- Object
- StrangeRequiresDetector
- Defined in:
- lib/kwala/lib/strange_requires_detector.rb
Instance Attribute Summary collapse
-
#print_strategy ⇒ Object
writeonly
Sets the attribute print_strategy.
Instance Method Summary collapse
- #check(dir, basedir = "") ⇒ Object
- #cut_base(filename, basename) ⇒ Object
-
#initialize(printer) ⇒ StrangeRequiresDetector
constructor
A new instance of StrangeRequiresDetector.
Constructor Details
#initialize(printer) ⇒ StrangeRequiresDetector
Returns a new instance of StrangeRequiresDetector.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/kwala/lib/strange_requires_detector.rb', line 65 def initialize(printer) @graph = Hash.new @printer = printer @file_filter = Proc.new do |files| files.find_all do |f| /tests\// !~ f && /extensions\// !~ f && /tools\// !~ f && /\/ms\// !~ f && /\/site\// !~f end end @req_filter = Proc.new do |reqs| reqs.find_all do |r| end end end |
Instance Attribute Details
#print_strategy=(value) ⇒ Object (writeonly)
Sets the attribute print_strategy
63 64 65 |
# File 'lib/kwala/lib/strange_requires_detector.rb', line 63 def print_strategy=(value) @print_strategy = value end |
Instance Method Details
#check(dir, basedir = "") ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/kwala/lib/strange_requires_detector.rb', line 85 def check(dir, basedir = "") files = ReqWalker.find_ruby_files(dir) @file_filter.call(files).each do |f| ReqWalker.get_requires(f).each do |r| r = ReqWalker.find_file(r) if r && /\/lib\/ruby\// !~ r f_base = Dir.new(File.dirname(f)) r_base = Dir.new(File.dirname(r)) # well, we assume that a directory models our "class category"... if f_base != r_base if r_base.is_subdir_of?(f_base) @printer.subdir_requirement(cut_base(f,basedir), cut_base(r,basedir)) else @printer.parent_dir_requirement(cut_base(f,basedir), cut_base(r,basedir)) end end end end end end |
#cut_base(filename, basename) ⇒ Object
81 82 83 |
# File 'lib/kwala/lib/strange_requires_detector.rb', line 81 def cut_base(filename, basename) filename.gsub(/^#{basename}/, '') end |