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



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

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
# File 'lib/bootscale/file_storage.rb', line 15

def dump(load_path, cache)
  File.open(cache_path(load_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