add initial Cache class

This commit is contained in:
Josh Holtrop 2013-07-05 11:07:02 -04:00
parent c008350d87
commit 5634b8856d
3 changed files with 44 additions and 0 deletions

View File

@ -1,4 +1,5 @@
require "rscons/builder"
require "rscons/cache"
require "rscons/environment"
require "rscons/version"

41
lib/rscons/cache.rb Normal file
View File

@ -0,0 +1,41 @@
require 'yaml'
require 'fileutils'
require 'digest/md5'
module Rscons
class Cache
# Constants
CACHE_FILE = '.rsconscache'
# Class Methods
def self.clear
FileUtils.rm_f(CACHE_FILE)
end
# Instance Methods
def initialize
@cache = YAML.load(File.read(CACHE_FILE)) rescue {}
end
def write
File.open(CACHE_FILE, 'w') do |fh|
fh.puts(YAML.dump(@cache))
end
end
def up_to_date?(file, deps = nil)
# TODO
end
def register_build(target, deps)
# TODO
end
# Private Instance Methods
private
def calculate_checksum(file)
Digest::MD5.hexdigest(File.read(file)).encode(__ENCODING__)
end
end
end

View File

@ -57,6 +57,8 @@ module Rscons
end
def process
cache = Cache.new
cache.write
end
alias_method :orig_method_missing, :method_missing