Sha256: c06c09a116c00a71cb810f703b95fbe293f34c85b06c6897130af59864873ebc
Contents?: true
Size: 773 Bytes
Versions: 15
Compression:
Stored size: 773 Bytes
Contents
require "digest/md5" module Ruco class FileStore def initialize(folder, options) @folder = folder @options = options end def set(key, value) `mkdir -p #{@folder}` unless File.exist? @folder File.write(file(key), serialize(value)) cleanup end def get(key) file = file(key) deserialize File.read(file) if File.exist?(file) end private def cleanup delete = `ls -t #{@folder}`.split("\n")[@options[:keep]..-1] || [] delete.each{|f| File.delete("#{@folder}/#{f}") } end def file(key) "#{@folder}/#{Digest::MD5.hexdigest(key)}.yml" end def serialize(value) Marshal.dump(value) end def deserialize(value) Marshal.load(value) end end end
Version data entries
15 entries across 15 versions & 1 rubygems