Module: Bootscale

Defined in:
lib/bootscale.rb,
lib/bootscale/entry.rb,
lib/bootscale/version.rb,
lib/bootscale/file_storage.rb,
lib/bootscale/cache_builder.rb

Defined Under Namespace

Classes: CacheBuilder, Entry, FileStorage

Constant Summary collapse

DOT_SO =
'.so'.freeze
DOT_RB =
'.rb'.freeze
VERSION =
'0.2.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.storageObject

Returns the value of attribute storage.



46
47
48
# File 'lib/bootscale.rb', line 46

def storage
  @storage
end

Class Method Details

.[](path) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/bootscale.rb', line 8

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

.cacheObject



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

def cache
  @cache ||= {}
end

.cache_builderObject



31
32
33
# File 'lib/bootscale.rb', line 31

def cache_builder
  @cache_builder ||= CacheBuilder.new
end

.cache_directory=(directory) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/bootscale.rb', line 48

def cache_directory=(directory)
  if directory
    require_relative 'bootscale/file_storage'
    self.storage = FileStorage.new(directory)
  else
    self.storage = nil
  end
end

.load_cacheObject



35
36
37
38
# File 'lib/bootscale.rb', line 35

def load_cache
  return unless storage
  storage.load($LOAD_PATH)
end

.regenerateObject



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

def regenerate
  @cache = load_cache || save_cache(cache_builder.generate($LOAD_PATH))
end

.save_cache(cache) ⇒ Object



40
41
42
43
44
# File 'lib/bootscale.rb', line 40

def save_cache(cache)
  return cache unless storage
  storage.dump($LOAD_PATH, cache)
  cache
end

.setup(options = {}) ⇒ Object



17
18
19
20
21
# File 'lib/bootscale.rb', line 17

def setup(options = {})
  self.cache_directory = options[:cache_directory]
  require_relative 'bootscale/setup'
  regenerate
end