Class: Bootscale::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/bootscale/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Cache

Returns a new instance of Cache.



7
8
9
10
# File 'lib/bootscale/cache.rb', line 7

def initialize
  @entries = {}
  regenerate
end

Instance Attribute Details

#entries ⇒ Object (readonly)

Returns the value of attribute entries.



5
6
7
# File 'lib/bootscale/cache.rb', line 5

def entries
  @entries
end

Instance Method Details

#[](path) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/bootscale/cache.rb', line 12

def [](path)
  if path.end_with?(DOT_RB) || path.end_with?(DOT_SO)
    @cache[path]
  else
    @cache["#{path}#{DOT_RB}"] || @cache["#{path}#{DOT_SO}"]
  end
end

#regenerate ⇒ Object



20
21
22
23
# File 'lib/bootscale/cache.rb', line 20

def regenerate
  ordered_entries = $LOAD_PATH.map { |path| entries.fetch(path) { Entry.new(path) } }
  @cache = Hash[ordered_entries.reverse.flat_map(&:features)]
end