Class: CacheManager

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

Overview

f = Files.new(Hash.new) f.add(“lib/beaver.rb”) pack = msg = MessagePack.pack(f) p pack p MessagePack::unpack(pack)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCacheManager

Returns a new instance of CacheManager.



70
71
72
73
74
75
76
77
# File 'lib/file.rb', line 70

def initialize
  begin
    @files = MessagePack::unpack(File.read $beaver.file_cache_file)
  rescue EOFError
    @files = Files.new(Hash.new)
    @files.add("__BEAVER__CONFIG__", $PROGRAM_NAME)
  end
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



68
69
70
# File 'lib/file.rb', line 68

def files
  @files
end

Instance Method Details

#saveObject



79
80
81
82
83
84
85
# File 'lib/file.rb', line 79

def save
  packed = MessagePack.pack(@files)
  unless Dir.exist? $beaver.cache_loc
    Dir.mkdir $beaver.cache_loc
  end
  File.binwrite($beaver.file_cache_file, packed)
end