Class: CTodo::LocalFS
- Inherits:
-
Object
- Object
- CTodo::LocalFS
- Defined in:
- lib/ctodo/localfs.rb
Instance Method Summary collapse
- #get_issues(issues) ⇒ Object
- #grep_for_todo(path, issues) ⇒ Object
-
#initialize(conf) ⇒ LocalFS
constructor
A new instance of LocalFS.
- #remove_common_path(file) ⇒ Object
- #tag_color(title) ⇒ Object
- #traverse(dir, issues) ⇒ Object
Constructor Details
#initialize(conf) ⇒ LocalFS
Returns a new instance of LocalFS.
11 12 13 14 15 16 17 |
# File 'lib/ctodo/localfs.rb', line 11 def initialize(conf) @enabled = true if @enabled @parent_dir = [:git_repo_dir, :hg_repo_dir, :cur_dir].map {|k| conf[k]}.select {|v| not v.nil?}.first @todo_labels = (conf[:all] ? ALL_LABELS : IMP_LABELS).join('|') end end |
Instance Method Details
#get_issues(issues) ⇒ Object
19 20 21 22 |
# File 'lib/ctodo/localfs.rb', line 19 def get_issues(issues) return if not @enabled traverse(@parent_dir, issues) end |
#grep_for_todo(path, issues) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ctodo/localfs.rb', line 38 def grep_for_todo(path, issues) GREP_EXT_EXCLUDE.each do |e| return if path.end_with?(e) end cf = CommentFilter.new(path) spath = remove_common_path(path) File.open(path, 'r') do |f| linenr = 1 f.readlines.map {|line| cf.filter(line)}.each do |line| m = line.match("[\\W](#{@todo_labels})\\(([\\w]+)\\):[\\W]+(.*)$") if not m.nil? loc = "#{spath}:#{linenr}" = [Tag.new(m[1], tag_color(m[1])), Tag.new(m[2], rgb4string(m[2]))] issues << Issue.new(m[3], loc, nil, ) next end m = line.match("[\\W](#{@todo_labels}):[\\W]+(.*)$") if not m.nil? loc = "#{spath}:#{linenr}" issues << Issue.new(m[2], loc, nil, Tag.new(m[1], tag_color(m[1]))) next end m = line.match("[\\W](#{@todo_labels})[\\W]+(.*)$") if not m.nil? loc = "#{spath}:#{linenr}" issues << Issue.new(m[2], loc, nil, Tag.new(m[1], tag_color(m[1]))) end linenr += 1 end end end |
#remove_common_path(file) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/ctodo/localfs.rb', line 70 def remove_common_path(file) begin return Pathname.new(file).relative_path_from(Pathname.new(Dir.getwd)) rescue ArgumentError => e return file end end |
#tag_color(title) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/ctodo/localfs.rb', line 78 def tag_color(title) case title when 'BUG' color = "ff0000" else color = "ffffff" end end |
#traverse(dir, issues) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ctodo/localfs.rb', line 24 def traverse(dir, issues) Dir.entries(dir).each do |e| next if TRAVERSE_EXCLUDE.include?(e) path = File.join(dir, e) # grep symlinked files but don't follow symlinked # directories if File.directory?(path) and not File.symlink?(path) traverse(path, issues) elsif File.file?(path) grep_for_todo(path, issues) end end end |