Sha256: ff0bd60a32217e861aea67270e7bf4bbeeb34ef4d1681d835986b4b917a2380e

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

module Serum
  class StaticFile
    # The cache of last modification times [path] -> mtime.
    @@mtimes = Hash.new

    # Initialize a new StaticFile.
    #
    # site - The Site.
    # base - The String path to the <source>.
    # dir  - The String path between <source> and the file.
    # name - The String filename of the file.
    def initialize(site, base, dir, name)
      @site = site
      @base = base
      @dir  = dir
      @name = name
    end

    # Returns source file path.
    def path
      File.join(@base, @dir, @name)
    end

    # Obtain destination path.
    #
    # dest - The String path to the destination dir.
    #
    # Returns destination file path.
    def destination(dest)
      File.join(dest, @dir, @name)
    end

    # Returns last modification time for this file.
    def mtime
      File.stat(path).mtime.to_i
    end

    # Is source path modified?
    #
    # Returns true if modified since last write.
    def modified?
      @@mtimes[path] != mtime
    end

    # Reset the mtimes cache (for testing purposes).
    #
    # Returns nothing.
    def self.reset_cache
      @@mtimes = Hash.new
      nil
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
serum-0.3.2 lib/serum/static_file.rb
serum-0.3.0 lib/serum/static_file.rb
serum-0.2.0 lib/serum/static_file.rb
serum-0.1.0 lib/serum/static_file.rb