Class: VimMate::ListedDirectory
- Inherits:
-
ListedFile
- Object
- ListedFile
- VimMate::ListedDirectory
- Includes:
- Enumerable
- Defined in:
- lib/vimmatelib/files.rb
Overview
A directory within the tree. Can contain files and other directories.
Instance Attribute Summary
Attributes inherited from ListedFile
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Yield each files and directory within this directory.
-
#icon_type ⇒ Object
The type of icon to use.
-
#initialize(path, exclude_file_list, parent = nil, &block) ⇒ ListedDirectory
constructor
Create a ListedDirectory from a path and an optional parent.
-
#refresh ⇒ Object
Refresh the files from this directory.
Methods inherited from ListedFile
Constructor Details
#initialize(path, exclude_file_list, parent = nil, &block) ⇒ ListedDirectory
Create a ListedDirectory from a path and an optional parent. A block must be passed so it can be called to signal changes.
114 115 116 117 118 119 |
# File 'lib/vimmatelib/files.rb', line 114 def initialize(path, exclude_file_list, parent = nil, &block) super(path, parent, &block) @files = Set.new @exclude_file_list = exclude_file_list refresh end |
Instance Method Details
#each(&block) ⇒ Object
Yield each files and directory within this directory
122 123 124 125 |
# File 'lib/vimmatelib/files.rb', line 122 def each(&block) @files.each(&block) self end |
#icon_type ⇒ Object
The type of icon to use
167 168 169 |
# File 'lib/vimmatelib/files.rb', line 167 def icon_type :folder end |
#refresh ⇒ Object
Refresh the files from this directory. If it doesn’t exist, the file is removed. If it didn’t exist before, the file is added.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/vimmatelib/files.rb', line 129 def refresh super # Find files to remove files_to_remove = Set.new all_paths = Set.new each do |file| file.refresh if File.exist? file.path all_paths << file.path else files_to_remove << file @tree_signal.call(:remove, file) end end @files -= files_to_remove # Find files to add begin Dir.foreach(@path) do |file| # Skip hidden files next if file =~ /^\./ path = File.join(@path, file) next if @exclude_file_list.any? {|f| path[-(f.size+1)..-1] == "/#{f}" } # Skip files that we already have next if all_paths.include? path # Add the new file @files << if File.directory? path ListedDirectory.new(path, @exclude_file_list, self, &@tree_signal) else ListedFile.new(path, self, &@tree_signal) end end rescue Errno::ENOENT end self end |