Class: SpeedGun::Store::FileStore
- Inherits:
-
SpeedGun::Store
- Object
- SpeedGun::Store
- SpeedGun::Store::FileStore
- Defined in:
- lib/speed_gun/store/file_store.rb
Instance Method Summary collapse
-
#initialize(basedir) ⇒ FileStore
constructor
A new instance of FileStore.
- #load(key) ⇒ Object
- #store(obj) ⇒ Object
Methods inherited from SpeedGun::Store
Constructor Details
#initialize(basedir) ⇒ FileStore
Returns a new instance of FileStore.
5 6 7 |
# File 'lib/speed_gun/store/file_store.rb', line 5 def initialize(basedir) @basedir = basedir end |
Instance Method Details
#load(key) ⇒ Object
20 21 22 23 24 25 26 |
# 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) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# 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 |