free_mutant/lib/mutant/cache.rb

33 lines
577 B
Ruby
Raw Normal View History

# 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