Class: FileSearcher
- Inherits:
-
Object
- Object
- FileSearcher
- Defined in:
- lib/exegesis/file_searcher.rb
Overview
class FileSearcher
Responsibilities:
Encapsulates an API for looking through a single directory of files,
sorting them into directories/files/whatever, and providing those path
lists on demand
NB:
The aim is to isolate the minimum API with this class, so that alternative
source backends could potentially be written, eg -- a backend for
distributed sourcetrees, or w/ files in Riak or S3 or whereever
Collaborators:
Used By:
Project, Directory
Uses:
Some system-level class like Dir, FileList, or Find
Instance Method Summary collapse
-
#content ⇒ Object
All of the content from the given path.
-
#directories ⇒ Object
All of the directories in the given path.
-
#files ⇒ Object
All of the files in the given path.
-
#initialize(parent, fs_interface = File) ⇒ FileSearcher
constructor
Create a new FileSearcher on the given path.
- #inspect ⇒ Object
Constructor Details
#initialize(parent, fs_interface = File) ⇒ FileSearcher
Create a new FileSearcher on the given path
22 23 24 25 |
# File 'lib/exegesis/file_searcher.rb', line 22 def initialize(parent, fs_interface = File) @fs_interface = fs_interface @parent = parent end |
Instance Method Details
#content ⇒ Object
All of the content from the given path
42 43 44 |
# File 'lib/exegesis/file_searcher.rb', line 42 def content Dir[File.join(parent.path, '*')] end |
#directories ⇒ Object
All of the directories in the given path
28 29 30 31 32 |
# File 'lib/exegesis/file_searcher.rb', line 28 def directories content. select { |s| fs_interface.directory?(s) }. map { |s| Directory.create(parent, fs_interface.basename(s)) } end |
#files ⇒ Object
All of the files in the given path
35 36 37 38 39 |
# File 'lib/exegesis/file_searcher.rb', line 35 def files content. select { |s| fs_interface.file?(s) }. map { |s| SourceFile.create(parent, fs_interface.basename(s)) } end |
#inspect ⇒ Object
46 47 48 |
# File 'lib/exegesis/file_searcher.rb', line 46 def inspect "FileSearcher(#{parent.path.inspect})" end |