#-- #++ #require 'digest/md5' module Reap # = Filer # # class Filer include TaskUtils attr_accessor :source def initialize( name, source, &build ) @name = name @source = [source].flatten @build = build end # Is this file task needed? Yes if it doesn't exist, or if its time # stamp is out of date. def needed? return true unless ::File.exist?( @name ) return true if out_of_date?( timestamp( @name ) ) false end # Check timestamp. def timestamp( name ) if ::File.exist?( name.to_s ) ::File.mtime( name.to_s ) else Time::EARLY # TODO replace with Facets' -Infinity class (?) end end # Are there any sources with a later time than the given timestamp? def out_of_date?( stamp ) @source.any? { |n| timestamp(n) > stamp } end # Build file. def build @build.call if needed? end alias_method :call, :build private #def salt( file ) # Digest::MD5.new( File.read( file ) ).hexdigest #end end end #module Reap