Module: Piggly::Util::Cacheable

Included in:
Compiler::TraceCompiler
Defined in:
lib/piggly/util/cacheable.rb

Instance Method Summary collapse

Instance Method Details

#cache_path(file) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/piggly/util/cacheable.rb', line 5

def cache_path(file)
  # Up to the last capitalized word of the class name
  classdir = self.class.name[/^(?:.+::)?(.+?)([A-Z][^A-Z]+)?$/, 1]

  # md5 the full path to prevent collisions
  full = ::File.expand_path(file)
  hash = Digest::MD5.hexdigest(::File.dirname(full))
  base = ::File.basename(file)

  @config.mkpath(::File.join(@config.cache_root, classdir), base)
end