Class: Drip::SimpleStore
- Inherits:
-
Object
show all
- Defined in:
- lib/drip.rb
Defined Under Namespace
Classes: Attic, AtticCache
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, option = {}) ⇒ SimpleStore
Returns a new instance of SimpleStore.
259
260
261
262
263
264
|
# File 'lib/drip.rb', line 259
def initialize(name, option={})
@name = name
@file = nil
cache_size = option.fetch(:cache_size, 8)
@cache = AtticCache.new(cache_size) if @name
end
|
Class Method Details
.each(name) ⇒ Object
247
248
249
250
251
252
253
254
255
256
257
|
# File 'lib/drip.rb', line 247
def self.each(name)
file = File.open(name, 'rb')
while true
pos = file.pos
key, value = Marshal.load(file)
yield(key, value, Attic.new(name, pos, value))
end
rescue EOFError
ensure
file.close if file
end
|
.reader(name) ⇒ Object
243
244
245
|
# File 'lib/drip.rb', line 243
def self.reader(name)
self.to_enum(:each, name)
end
|
Instance Method Details
#write(key, value) ⇒ Object
266
267
268
269
270
271
272
273
|
# File 'lib/drip.rb', line 266
def write(key, value)
return value unless @name
@file = File.open(@name, 'a+b') unless @file
pos = @file.pos
Marshal.dump([key, value], @file)
@file.flush
@cache.push(Attic.new(@name, pos, value))
end
|