Class: Ruber::ProjectDirScanner
- Defined in:
- lib/ruber/project_dir_scanner.rb
Instance Method Summary collapse
- #file_in_project?(file) ⇒ Boolean
-
#initialize(prj) ⇒ ProjectDirScanner
constructor
A new instance of ProjectDirScanner.
- #project_files ⇒ Object
Constructor Details
#initialize(prj) ⇒ ProjectDirScanner
Returns a new instance of ProjectDirScanner.
37 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 |
# File 'lib/ruber/project_dir_scanner.rb', line 37 def initialize prj super @project = prj #The /? at the end is there to avoid depending on whether Project#project_directory #returns a string ending with / or not @regexp = %r[^#{Regexp.quote @project.project_directory}/?] make_rules @watcher = KDE::DirWatch.new self do add_dir prj.project_directory, KDE::DirWatch::WatchFiles | KDE::DirWatch::WatchSubDirs end @watcher.connect(SIGNAL('created(QString)')) do |f| emit file_added(f) if file_in_project? f end @watcher.connect(SIGNAL('deleted(QString)')) do |f| emit file_removed(f) if file_in_project? f end @project.connect(SIGNAL('option_changed(QString, QString)')) do |g, n| if g == 'general' and n == 'project_files' if @project[:general, :project_files] != @rules make_rules emit rules_changed end end end @watcher.start_scan false end |
Instance Method Details
#file_in_project?(file) ⇒ Boolean
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ruber/project_dir_scanner.rb', line 65 def file_in_project? file if file.start_with? '/' file = file.dup return false unless file.sub! @regexp, '' end return nil if file.end_with? '/' if file =~ %r{^([\w+-.]+)://(.+)} if $1 == 'file' then file = $2 else return false end end return false if @exclude_regexp =~ file return false if @exclude_files.include? file return true if @extensions.any?{|e| File.fnmatch?(e, file, File::FNM_DOTMATCH)} return true if @include_regexp =~ file or @include_files.include? file false end |
#project_files ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ruber/project_dir_scanner.rb', line 83 def project_files res = Set.new dir = @project.project_directory Ruber[:app].chdir dir do Find.find '.' do |f| next if File.directory? f #remove the leading './' f = f[2..-1] res << File.join(dir, f) if file_in_project? f end end res end |