free_mutant/lib/mutant/cache.rb
2015-07-02 03:35:54 +00:00

29 lines
496 B
Ruby

module Mutant
# An AST cache
class Cache
include Equalizer.new, Adamantium::Mutable
# Initialize object
#
# @return [undefined]
#
# @api private
def initialize
@cache = {}
end
# Return node for file
#
# @param [#to_s] path
#
# @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