class SpeedGun::Store::FileStore
Public Class Methods
new(basedir)
click to toggle source
# File lib/speed_gun/store/file_store.rb, line 5 def initialize(basedir) @basedir = basedir end
Public Instance Methods
load(key)
click to toggle source
# File lib/speed_gun/store/file_store.rb, line 20 def load(key) filepath = pathnize(key) return nil unless File.exist?(filepath) msg = File.open(filepath, 'rb', &:read) deserialize(key, msg) end
store(obj)
click to toggle source
# File lib/speed_gun/store/file_store.rb, line 9 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
Private Instance Methods
pathnize(key)
click to toggle source
# File lib/speed_gun/store/file_store.rb, line 30 def pathnize(key) klass, id = *key.split('/', 2) File.join(@basedir, *klass.split('::'), id) end