Class: Bootscale::FileStorage

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

Instance Method Summary collapse

Constructor Details

#initialize(directory) ⇒ FileStorage

Returns a new instance of FileStorage.



6
7
8
# File 'lib/bootscale/file_storage.rb', line 6

def initialize(directory)
  @directory = directory
end

Instance Method Details

#cache_path(load_path) ⇒ Object



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

def cache_path(load_path)
  hash = Digest::MD5.hexdigest((load_path + [RUBY_VERSION, Bootscale::VERSION, MessagePack::VERSION]).join('|'))
  File.join(@directory, "bootscale-#{hash}.msgpack")
end

#dump(load_path, cache) ⇒ Object



15
16
17
18
19
20
# File 'lib/bootscale/file_storage.rb', line 15

def dump(load_path, cache)
  path = cache_path(load_path)
  return if File.exist?(path)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'wb+') { |f| f.write(MessagePack.dump(cache)) }
end

#load(load_path) ⇒ Object



10
11
12
13
# File 'lib/bootscale/file_storage.rb', line 10

def load(load_path)
  path = cache_path(load_path)
  MessagePack.load(File.read(path)) if File.exist?(path)
end