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
LEADING_SLASH =
'/'.freeze
VERSION =
'0.2.2'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.storageObject

Returns the value of attribute storage.



48
49
50
# File 'lib/bootscale.rb', line 48

def storage
  @storage
end

Class Method Details

.[](path) ⇒ Object



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

def [](path)
  path = path.to_s
  return if path.start_with?(LEADING_SLASH)
  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



29
30
31
# File 'lib/bootscale.rb', line 29

def cache
  @cache ||= {}
end

.cache_builderObject



33
34
35
# File 'lib/bootscale.rb', line 33

def cache_builder
  @cache_builder ||= CacheBuilder.new
end

.cache_directory=(directory) ⇒ Object



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

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

.load_cacheObject



37
38
39
40
# File 'lib/bootscale.rb', line 37

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

.regenerateObject



25
26
27
# File 'lib/bootscale.rb', line 25

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

.save_cache(cache) ⇒ Object



42
43
44
45
46
# File 'lib/bootscale.rb', line 42

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

.setup(options = {}) ⇒ Object



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

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