Class: Bootscale::FileStorage
- Inherits:
-
Object
- Object
- Bootscale::FileStorage
- Defined in:
- lib/bootscale/file_storage.rb
Constant Summary collapse
- Serializer =
Marshal
Instance Method Summary collapse
- #cache_path(load_path) ⇒ Object
- #dump(load_path, cache) ⇒ Object
-
#initialize(directory) ⇒ FileStorage
constructor
A new instance of FileStorage.
- #load(load_path) ⇒ Object
Constructor Details
#initialize(directory) ⇒ FileStorage
Returns a new instance of FileStorage.
5 6 7 |
# File 'lib/bootscale/file_storage.rb', line 5 def initialize(directory) @directory = directory end |
Instance Method Details
#cache_path(load_path) ⇒ Object
24 25 26 27 |
# File 'lib/bootscale/file_storage.rb', line 24 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
14 15 16 17 18 19 |
# File 'lib/bootscale/file_storage.rb', line 14 def dump(load_path, cache) path = cache_path(load_path) return if File.exist?(path) FileUtils.mkdir_p(File.dirname(path)) File.write(path, Serializer.dump(cache)) end |
#load(load_path) ⇒ Object
9 10 11 12 |
# File 'lib/bootscale/file_storage.rb', line 9 def load(load_path) path = cache_path(load_path) Serializer.load(File.read(path)) if File.exist?(path) end |