Module: Piggly::FileCache::ClassMethods
- Defined in:
- lib/piggly/filecache.rb
Instance Method Summary collapse
-
#cache_path(file) ⇒ Object
Maps source path to cache path, like /home/user/foo.sql => piggly/cache/#MD5(‘/home/user’)/#BaseClass/foo.sql.
Instance Method Details
#cache_path(file) ⇒ Object
Maps source path to cache path, like /home/user/foo.sql => piggly/cache/#MD5(‘/home/user’)/#BaseClass/foo.sql
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/piggly/filecache.rb', line 24 def cache_path(file) # up to the last capitalized word of the class name subdir = name[/^(?:.+::)?(.+?)([A-Z][^A-Z]+)?$/, 1] root = File.join(Config.cache_root, subdir) # md5 the full path to prevent collisions full = File.(file) base = File.basename(full) hash = Digest::MD5.hexdigest(File.dirname(full)) Config.mkpath(File.join(Config.cache_root, hash, subdir), base) end |