2013-06-27 16:18:07 -04:00
|
|
|
module Mutant
|
|
|
|
# An AST cache
|
|
|
|
class Cache
|
2014-06-30 09:06:57 -04:00
|
|
|
include Equalizer.new, Adamantium::Mutable
|
2013-06-27 16:18:07 -04:00
|
|
|
|
|
|
|
# Initialize object
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def initialize
|
|
|
|
@cache = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return node for file
|
|
|
|
#
|
2014-06-26 17:43:58 -04:00
|
|
|
# @param [#to_s] path
|
|
|
|
#
|
2013-06-27 16:18:07 -04:00
|
|
|
# @return [AST::Node]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def parse(path)
|
|
|
|
@cache.fetch(path) do
|
2014-06-09 10:56:13 -04:00
|
|
|
@cache[path] = Parser::CurrentRuby.parse(File.read(path))
|
2013-06-27 16:18:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end # Cache
|
|
|
|
end # Mutant
|