module Rake

Rote adds the following methods to the Rake module. All this cool stuff was contributed by Jonathan Paisley (<jp-www at dcs gla ac uk>)

Public Class Methods

cache_dir() click to toggle source
# File lib/rote/cache.rb, line 31
def cache_dir; @cache_dir ||= ".rake_cache"; end
cache_dir=(val) click to toggle source

Directory for storing Rake dependency cache

# File lib/rote/cache.rb, line 30
def cache_dir=(val); @cache_dir = val; end
cache_enabled=(b) click to toggle source

Enable or disable dependency caching.

# File lib/rote/cache.rb, line 49
def cache_enabled=(b); @cache_enabled = b; end
cache_enabled?() click to toggle source

Determine whether dependency caching is enabled

# File lib/rote/cache.rb, line 40
def cache_enabled?
  if @cache_enabled.nil?
    @cache_enabled = !ENV['NO_RAKE_CACHE']
  else 
    @cache_enabled
  end
end
cached_dependencies() click to toggle source

Hash of current cached dependencies

# File lib/rote/cache.rb, line 34
def cached_dependencies; @cached_dependencies ||= {}; end
current_task() click to toggle source

Reference to current task being executed

# File lib/rote/cache.rb, line 38
def current_task; task_stack.last; end
dependencies_file() click to toggle source
# File lib/rote/cache.rb, line 32
def dependencies_file; File.join(cache_dir,"dependencies.yaml"); end
register_dependency(deps, task = nil) click to toggle source

Use this method to dynamically register one or more files as dependencies of the currently executing task (or the specified task if non-nil).

# File lib/rote/cache.rb, line 54
def register_dependency(deps, task = nil)
  task = (current_task.name if current_task) unless task
  if task then
    file task => deps
     (cached_dependencies[task] ||= []) << deps
  end
end
task_stack() click to toggle source

Array representing current tasks being executed

# File lib/rote/cache.rb, line 36
def task_stack; @tasks ||= []; end

Protected Class Methods

load_cached_dependencies() click to toggle source

Load cached dependencies, unless they’re already loaded. This method is called during task invocation, with the effect that cached deps are loaded from yaml on the first invoke.

An at_exit handler is installed to save the dependencies when rake exits.

# File lib/rote/cache.rb, line 127
def self.load_cached_dependencies
  return unless !$CACHEDEPS_LOADED and Rake.cache_enabled?    
  
  at_exit { self.save_cached_dependencies }

  return unless File.exists?(dependencies_file)
  YAML.load(File.read(dependencies_file)).each do |task,deps|
    deps.each do |dep|
      register_dependency(dep, task)
    end
  end
  
  $CACHEDEPS_LOADED = true
end
save_cached_dependencies() click to toggle source
# File lib/rote/cache.rb, line 142
def self.save_cached_dependencies
  return if cached_dependencies.empty? || !Rake.cache_enabled?
  
  mkdir_p cache_dir unless File.exists?(cache_dir)
  deps = {}
  cached_dependencies.each do |k,v|
    deps[k] = v.flatten.uniq
  end
  File.open(dependencies_file,"w") { |fp| fp.write YAML.dump(deps) }
end