Class: Evilution::SpecAstCache

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/spec_ast_cache.rb

Defined Under Namespace

Classes: Block

Instance Method Summary collapse

Constructor Details

#initialize(max_files: DEFAULT_MAX_FILES, max_blocks: DEFAULT_MAX_BLOCKS) ⇒ SpecAstCache

Returns a new instance of SpecAstCache.



20
21
22
23
24
25
# File 'lib/evilution/spec_ast_cache.rb', line 20

def initialize(max_files: DEFAULT_MAX_FILES, max_blocks: DEFAULT_MAX_BLOCKS)
  @max_files = max_files
  @max_blocks = max_blocks
  @entries = {}
  @total_blocks = 0
end

Instance Method Details

#cached?(path) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/evilution/spec_ast_cache.rb', line 39

def cached?(path)
  @entries.key?(path)
end

#fetch(path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/evilution/spec_ast_cache.rb', line 27

def fetch(path)
  if @entries.key?(path)
    blocks = @entries.delete(path)
    @entries[path] = blocks
    return blocks
  end

  blocks = parse(path)
  insert(path, blocks)
  blocks
end