Sha256: 3fd6808de06130849d7cc1882dfcf138a898580d1b455cc102b6f2b4b0f79a59

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 KB

Contents

require 'rubygems' if RUBY_VERSION < '1.9'
require 'rake/tasklib'
require 'fileutils'

module Rake

  module Microsecond
  # Compensate for file systems with 1s resolution

    class FileTask < Task

      attr_accessor :timestamp

      def self.define_task( *args, &block )
        task = super( *args, &block )
        task.timestamp = nil
        task
      end

      def needed?
        return true if ! File.exist?( self.name )
        @timestamp = File.stat( self.name ).mtime if @timestamp.nil?
        return self.prerequisites.any? { | n | ! application[n].timestamp.nil? && application[n].timestamp > @timestamp }
      end

      def execute(*args)
        @timestamp = Time.now
        super(*args)
      end

    end

    class DirectoryTask < Task

      include FileUtils

      attr_accessor :timestamp
      attr_accessor :path

      def self.define_task( *args, &block )
        task           = super(*args, &block)
        task.path      = args[0]
        task.timestamp = nil
        task
      end

      def needed?
        exists = File.directory?(self.path)
        if exists && @timestamp.nil?
          @timestamp = File.stat(self.path).mtime
        end
        ! exists
      end

      def execute(*args)
        mkdir_p self.path, :verbose => false
        @timestamp = Time.now
        super(*args)
      end

    end

  end

end

def microsecond_file(*args, &block)
  Rake::Microsecond::FileTask.define_task(*args, &block)
end

def microsecond_directory(*args, &block)
  Rake::Microsecond::DirectoryTask.define_task(*args, &block)
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rake-builder-0.0.19 lib/rake/microsecond.rb
rake-builder-0.0.18 lib/rake/microsecond.rb
rake-builder-0.0.17 lib/rake/microsecond.rb