lib/sitediff/cache.rb in sitediff-0.0.5 vs lib/sitediff/cache.rb in sitediff-0.0.6
- old
+ new
@@ -6,14 +6,17 @@
class SiteDiff
class Cache
attr_accessor :read_tags, :write_tags
def initialize(opts = {})
- @dir = opts[:dir] || '.'
@create = opts[:create]
+
+ # Read and Write tags are sets that can contain :before and :after
+ # They indicate whether we should use the cache for reading or writing
@read_tags = Set.new
@write_tags = Set.new
+ @dir = opts[:directory] || '.'
end
# Is a tag cached?
def tag?(tag)
File.directory?(File.join(@dir, 'snapshot', tag.to_s))
@@ -60,8 +63,15 @@
end
def key(tag, path)
# Ensure encoding stays the same!
Marshal.dump([tag, path.encode('UTF-8')])
+ end
+
+ def get_dir(directory)
+ # Create the dir. Must go before cache initialization!
+ @dir = Pathname.new(directory || '.')
+ @dir.mkpath unless @dir.directory?
+ @dir.to_s
end
end
end