free_mutant/lib/mutant/cache.rb
Markus Schirp d0d1bb2464 Normalize ASTs prior to mutation
This avoids situartions where the source contains (begin, other)
nodes that get mutated to (other) where there is no difference in the
source.

Closes #198
2014-06-08 11:53:50 +00:00

32 lines
577 B
Ruby

# encoding: utf-8
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] = Unparser::Preprocessor.run(Parser::CurrentRuby.parse(File.read(path)))
end
end
end # Cache
end # Mutant