Class: Riml::RewrittenASTCache

Inherits:
Object
  • Object
show all
Defined in:
lib/riml/rewritten_ast_cache.rb

Instance Method Summary collapse

Constructor Details

#initializeRewrittenASTCache

Returns a new instance of RewrittenASTCache.



3
4
5
6
# File 'lib/riml/rewritten_ast_cache.rb', line 3

def initialize
  @cache = {}
  @ast_classes_registered_cache = {}
end

Instance Method Details

#[](filename) ⇒ Object



8
9
10
# File 'lib/riml/rewritten_ast_cache.rb', line 8

def [](filename)
  @cache[filename]
end

#clearObject



18
19
20
21
# File 'lib/riml/rewritten_ast_cache.rb', line 18

def clear
  @cache.clear
  @ast_classes_registered_cache.clear
end

#fetch(filename) ⇒ Object



12
13
14
15
16
# File 'lib/riml/rewritten_ast_cache.rb', line 12

def fetch(filename)
  ast = @cache[filename]
  return ast if ast
  @cache[filename] = yield
end

#fetch_classes_registered(ast) ⇒ Object



27
28
29
# File 'lib/riml/rewritten_ast_cache.rb', line 27

def fetch_classes_registered(ast)
  @ast_classes_registered_cache[ast.object_id] || {}
end

#save_classes_registered(ast, class_diff) ⇒ Object



23
24
25
# File 'lib/riml/rewritten_ast_cache.rb', line 23

def save_classes_registered(ast, class_diff)
  @ast_classes_registered_cache[ast.object_id] = class_diff
end