class Webgen::Source::FileSystem

This class is used to read source paths from a directory in the file system.

Attributes

glob[R]

The glob (see Dir.glob for details) that is used to specify which paths under the root path should be returned by paths.

root[R]

The root path from which paths are read.

Public Class Methods

new(website, root, glob = '{*,**/*}') click to toggle source

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.

   # File lib/webgen/source/file_system.rb
22 def initialize(website, root, glob = '{*,**/*}')
23   @root = File.absolute_path(root, website.directory)
24   @glob = glob
25 end

Public Instance Methods

paths() click to toggle source

Return all paths under the root path which match the glob.

   # File lib/webgen/source/file_system.rb
28 def paths
29   @paths ||= Dir.glob(File.join(@root, @glob), File::FNM_DOTMATCH|File::FNM_CASEFOLD).collect do |f|
30     next unless File.exist?(f) && f !~ /\/\.\.$/ # handle invalid links
31     temp = Pathname.new(f.sub(/^#{Regexp.escape(@root)}\/?/, '/')).cleanpath.to_s
32     temp += '/' if File.directory?(f) && temp[-1] != ?/
33     Path.new(temp, 'modified_at' => File.mtime(f)) {|mode| File.open(f, mode)}
34   end.compact.to_set
35 end