free_mutant/lib/mutant/cache.rb
Markus Schirp 49133680ee Add AST caching for subject matcher
At least this dramatically speeds up unit tests. And this is a good
thing.
2013-06-27 22:18:07 +02:00

30 lines
530 B
Ruby

module Mutant
# An AST cache
class Cache
# This is explicitly empty! Ask me if you are interested in reasons :D
include Equalizer.new
# Initialize object
#
# @return [undefined]
#
# @api private
#
def initialize
@cache = {}
end
# Return node for file
#
# @return [AST::Node]
#
# @api private
#
def parse(path)
@cache.fetch(path) do
@cache[path] = Parser::CurrentRuby.parse(File.read(path))
end
end
end # Cache
end # Mutant