class Mtodos::Cache
Local cache
Public Class Methods
new()
click to toggle source
# File lib/mtodos.rb, line 9 def initialize @cache_filename = 'mtodos.cache' @cache_file = File.join(Dir.pwd, @cache_filename) if File.file?(@cache_file) @hash = Marshal.load(File.read(@cache_file)) else @hash = {} File.write(@cache_file, Marshal.dump(@hash)) end end
Public Instance Methods
get(key)
click to toggle source
# File lib/mtodos.rb, line 27 def get(key) begin @hash = Marshal.load(File.read(@cache_file)) rescue Errno::ENOENT @hash = {} end having?(key) end
having?(key)
click to toggle source
# File lib/mtodos.rb, line 36 def having?(key) if @hash[key] true else fail NotFound, 'NotFound key' end end
set(key, value)
click to toggle source
# File lib/mtodos.rb, line 22 def set(key, value) @hash[key] = value File.write(@cache_file, Marshal.dump(@hash)) end