Class: FileSearcher

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(parent, fs_interface = File) ⇒ FileSearcher

Create a new FileSearcher on the given path

Parameters:

  • parent (Directory)

    the parent directory to search downward from



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

#contentObject

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

#directoriesObject

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

#filesObject

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

#inspectObject



46
47
48
# File 'lib/exegesis/file_searcher.rb', line 46

def inspect
  "FileSearcher(#{parent.path.inspect})"
end