# # File 'cachemanager.rb' created on 28 gen 2008 at 18:31:05. # # See 'dokkit.rb' or +LICENSE+ for licence information. # # (C) 2006, 2007 Andrea Fazzi (and contributors). # require 'singleton' require 'rake' require 'yaml' module Dokkit class CacheManager include Singleton def init(cache_filename = 'deps.yaml', cache_dir = '.cache') @cache_filename = cache_filename @cache_dir = cache_dir @complete_cache_filename = File.join(cache_dir, cache_filename) @deps = {} load if File.exists?(@complete_cache_filename) at_exit { save } end def add_dependency(task_name, dep) @deps[task_name] ||= [] @deps[task_name] << dep unless (dep.nil? or @deps[task_name].include?(dep)) end def load File.open(@complete_cache_filename) do |file| @deps = YAML::load(file) @deps.each do |task, dep| file task => dep end end end def save unless @deps.empty? mkdir_p(cache_dir, :verbose => false) unless File.exists?(cache_dir) File.open(@complete_cache_filename, 'w') do |file| file.write YAML::dump(@deps) end end end def clean_deps @deps.clear end def clean clean_deps rm_rf(cache_dir, :verbose => false) unless cache_dir == '.' end def deps @deps end def cache_dir @cache_dir end def cache_filename @cache_filename end end end