Class: Webgen::Source::FileSystem
- Inherits:
-
Object
- Object
- Webgen::Source::FileSystem
- Defined in:
- lib/webgen/source/filesystem.rb
Overview
This class is used to read source paths from a directory in the file system.
Defined Under Namespace
Classes: Path
Instance Attribute Summary collapse
-
#glob ⇒ Object
readonly
The glob (see Dir.glob for details) that is used to specify which paths under the root path should be returned by #paths.
-
#root ⇒ Object
readonly
The root path from which paths read.
Instance Method Summary collapse
-
#initialize(root, glob = '**/*') ⇒ FileSystem
constructor
Create a new file system source for the root path
root
using the providedglob
. -
#paths ⇒ Object
Return all paths under #root which match #glob.
Constructor Details
#initialize(root, glob = '**/*') ⇒ FileSystem
Create a new file system source for the root path root
using the provided glob
.
39 40 41 42 43 44 45 46 |
# File 'lib/webgen/source/filesystem.rb', line 39 def initialize(root, glob = '**/*') if root =~ /^([a-zA-Z]:|\/)/ @root = root else @root = File.join(WebsiteAccess.website.directory, root) end @glob = glob end |
Instance Attribute Details
#glob ⇒ Object (readonly)
The glob (see Dir.glob for details) that is used to specify which paths under the root path should be returned by #paths.
36 37 38 |
# File 'lib/webgen/source/filesystem.rb', line 36 def glob @glob end |
#root ⇒ Object (readonly)
The root path from which paths read.
32 33 34 |
# File 'lib/webgen/source/filesystem.rb', line 32 def root @root end |
Instance Method Details
#paths ⇒ Object
Return all paths under #root which match #glob.
49 50 51 52 53 54 55 56 57 |
# File 'lib/webgen/source/filesystem.rb', line 49 def paths @paths ||= Dir.glob(File.join(@root, @glob), File::FNM_DOTMATCH|File::FNM_CASEFOLD).to_set.collect do |f| next unless File.exists?(f) # handle invalid links temp = Pathname.new(f.sub(/^#{Regexp.escape(@root)}\/?/, '/')).cleanpath.to_s temp += '/' if File.directory?(f) && temp[-1] != ?/ path = Path.new(temp, f) path end.compact end |