Sha256: 4f9f1ec39cfa027c74821d5e8bbf68ebae19826f262365432fc5570e8e95b10a

Contents?: true

Size: 1.76 KB

Versions: 10

Compression:

Stored size: 1.76 KB

Contents

require 'pathname'
require 'webgen/websiteaccess'
require 'webgen/path'

module Webgen

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

    # A special Webgen::Path class for handling with file system paths.
    class Path < Webgen::Path

      # Create a new object with absolute path +path+ for the file system path +fs_path+.
      def initialize(path, fs_path)
        super(path) { File.open(fs_path, 'rb') }
        @fs_path = fs_path
        WebsiteAccess.website.cache[[:fs_path, @fs_path]] = File.mtime(@fs_path)
        @meta_info['modified_at'] = File.mtime(@fs_path)
      end

      # Return +true+ if the file system path used by the object has been modified.
      def changed?
        data = WebsiteAccess.website.cache[[:fs_path, @fs_path]]
        File.mtime(@fs_path) > data
      end

    end

    # The root path from which paths read.
    attr_reader :root

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

    # Create a new file system source for the root path +root+ using the provided +glob+.
    def initialize(root, glob = '**/*')
      if root =~ /^([a-zA-Z]:|\/)/
        @root = root
      else
        @root = File.join(WebsiteAccess.website.directory, root)
      end
      @glob = glob
    end

    # Return all paths under #root which match #glob.
    def paths
      @paths ||= Dir.glob(File.join(@root, @glob), File::FNM_DOTMATCH|File::FNM_CASEFOLD).to_set.collect! do |f|
        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
    end

  end

end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
gettalong-webgen-0.5.4.20080929 lib/webgen/source/filesystem.rb
gettalong-webgen-0.5.5.20081001 lib/webgen/source/filesystem.rb
gettalong-webgen-0.5.5.20081010 lib/webgen/source/filesystem.rb
gettalong-webgen-0.5.5.20081012 lib/webgen/source/filesystem.rb
gettalong-webgen-0.5.6.20081020 lib/webgen/source/filesystem.rb
webgen-0.5.4 lib/webgen/source/filesystem.rb
webgen-0.5.3 lib/webgen/source/filesystem.rb
webgen-0.5.2 lib/webgen/source/filesystem.rb
webgen-0.5.5 lib/webgen/source/filesystem.rb
webgen-0.5.6 lib/webgen/source/filesystem.rb