Sha256: 998c70323ee65c1fb6ed251c6f7babd0001f9e96d4e237917a9bbe16bb2497e4
Contents?: true
Size: 696 Bytes
Versions: 3
Compression:
Stored size: 696 Bytes
Contents
require 'fileutils' require 'speed_gun/store' class SpeedGun::Store::FileStore < SpeedGun::Store def initialize(basedir) @basedir = basedir end def store(obj) key, val = serialize(obj) filepath = pathnize(key) dirname = File.dirname(filepath) FileUtils.mkdir_p(dirname) unless File.directory?(dirname) File.open(filepath, 'wb') do |fp| fp.write(val) end end def load(key) filepath = pathnize(key) return nil unless File.exist?(filepath) msg = File.open(filepath, 'rb', &:read) deserialize(key, msg) end private def pathnize(key) klass, id = *key.split('/', 2) File.join(@basedir, *klass.split('::'), id) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
speed_gun-2.0.1 | lib/speed_gun/store/file_store.rb |
speed_gun-2.0.0 | lib/speed_gun/store/file_store.rb |
speed_gun-2.0.0.pre.alpha.1 | lib/speed_gun/store/file_store.rb |