Class: Webgen::Source::FileSystem
- Inherits:
-
Object
- Object
- Webgen::Source::FileSystem
- Defined in:
- lib/webgen/source/file_system.rb
Overview
This class is used to read source paths from a directory in the file system.
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 are read.
Instance Method Summary collapse
-
#initialize(website, root, glob = '{*,**/*}') ⇒ FileSystem
constructor
Create a new file system source for the root path
root
using the providedglob
. -
#paths ⇒ Object
Return all paths under the root path which match the glob.
Constructor Details
#initialize(website, root, glob = '{*,**/*}') ⇒ FileSystem
Create a new file system source for the root path root
using the provided glob
. If root
is not an absolute path, the website directory will be prepended.
23 24 25 26 |
# File 'lib/webgen/source/file_system.rb', line 23 def initialize(website, root, glob = '{*,**/*}') @root = File.absolute_path(root, website.directory) @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.
19 20 21 |
# File 'lib/webgen/source/file_system.rb', line 19 def glob @glob end |
#root ⇒ Object (readonly)
The root path from which paths are read.
15 16 17 |
# File 'lib/webgen/source/file_system.rb', line 15 def root @root end |
Instance Method Details
#paths ⇒ Object
Return all paths under the root path which match the glob.
29 30 31 32 33 34 35 36 |
# File 'lib/webgen/source/file_system.rb', line 29 def paths @paths ||= Dir.glob(File.join(@root, @glob), File::FNM_DOTMATCH|File::FNM_CASEFOLD).collect do |f| next unless File.exist?(f) && f !~ /\/\.\.$/ # handle invalid links temp = Pathname.new(f.sub(/^#{Regexp.escape(@root)}\/?/, '/')).cleanpath.to_s temp += '/' if File.directory?(f) && temp[-1] != ?/ Path.new(temp, 'modified_at' => File.mtime(f)) {|mode| File.open(f, mode)} end.compact.to_set end |