Class: DirectoryScanner
- Inherits:
-
Object
- Object
- DirectoryScanner
- Defined in:
- lib/mvn_plugin_config/directory_scanner.rb
Instance Method Summary collapse
- #directories_in_parent(parentPath) ⇒ Object
-
#initialize ⇒ DirectoryScanner
constructor
A new instance of DirectoryScanner.
- #on_dir(&action) ⇒ Object
- #on_file(&action) ⇒ Object
- #scan_subtree(parentPath) ⇒ Object
Constructor Details
#initialize ⇒ DirectoryScanner
Returns a new instance of DirectoryScanner.
3 4 5 6 |
# File 'lib/mvn_plugin_config/directory_scanner.rb', line 3 def initialize @fileAction = nil @dirAction = nil end |
Instance Method Details
#directories_in_parent(parentPath) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mvn_plugin_config/directory_scanner.rb', line 16 def directories_in_parent(parentPath) directories = [] Dir.open(parentPath) do |dir| for file in dir next if file == '.'; next if file == '..'; path = parentPath + File::Separator + file if File.directory? path directories << file end end end directories end |
#on_dir(&action) ⇒ Object
12 13 14 |
# File 'lib/mvn_plugin_config/directory_scanner.rb', line 12 def on_dir(&action) @dirAction = action end |
#on_file(&action) ⇒ Object
8 9 10 |
# File 'lib/mvn_plugin_config/directory_scanner.rb', line 8 def on_file(&action) @fileAction = action end |
#scan_subtree(parentPath) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mvn_plugin_config/directory_scanner.rb', line 32 def scan_subtree(parentPath) Dir.open(parentPath) do |dir| for file in dir next if file == '.'; next if file == '..'; path = parentPath + File::Separator + file if File.directory? path @dirAction.call(file, path) unless @dirAction.nil? scan_subtree(path) else @fileAction.call(file, path) unless @fileAction.nil? end end end end |