Class: Ruber::ProjectDirScanner
- Inherits:
-
Qt::Object
- Object
- Qt::Object
- Ruber::ProjectDirScanner
- Defined in:
- lib/ruber/project_dir_scanner.rb,
lib/ruber/project_dir_scanner.rb
Instance Method Summary (collapse)
- - (Boolean) file_in_project?(file)
- - (Boolean) in_project?(file)
-
- (ProjectDirScanner) initialize(prj)
constructor
A new instance of ProjectDirScanner.
- - (Object) make_rules private
- - (Object) project_files
Signal Summary
Constructor Details
- (ProjectDirScanner) initialize(prj)
A new instance of ProjectDirScanner
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ruber/project_dir_scanner.rb', line 28 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
- (Boolean) file_in_project?(file)
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 |
- (Boolean) in_project?(file)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ruber/project_dir_scanner.rb', line 47 def 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 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 |
- (Object) make_rules (private)
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ruber/project_dir_scanner.rb', line 70 def make_rules rules = @project[:general, :project_files] @include_regexp = Regexp.union(*(rules[:include].select{|r| r.is_a?(Regexp)})) @exclude_regexp = Regexp.union(*(rules[:exclude].select{|r| r.is_a?(Regexp)})) @exclude_files = rules[:exclude].select{|rule| rule.is_a? String}.map{|f| f.sub(%r{^\./}, '')} @include_files = rules[:include].select{|rule| rule.is_a? String}.map{|f| f.sub(%r{^\./}, '')} @include_files-= @exclude_files @extensions = rules[:extensions] @rules = YAML.load(YAML.dump rules) end |
- (Object) project_files
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ruber/project_dir_scanner.rb', line 64 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 |
Signal Details
- rules_changed
- file_added(QString arg1)
- file_removed(QString arg1)