Class: Gel::DB::File
Instance Method Summary
collapse
#nested?, #owned?, #read?, #write?
Methods inherited from Gel::DB
new
Constructor Details
#initialize(root, name) ⇒ File
Returns a new instance of File.
256
257
258
|
# File 'lib/gel/db.rb', line 256
def initialize(root, name)
@path = Pathname.new("#{root}/#{name}")
end
|
Instance Method Details
#[](key) ⇒ Object
279
280
281
282
283
284
|
# File 'lib/gel/db.rb', line 279
def [](key)
child = @path.join(key)
if child.exist?
Marshal.load(child.binread)
end
end
|
#[]=(key, value) ⇒ Object
286
287
288
289
290
291
292
293
|
# File 'lib/gel/db.rb', line 286
def []=(key, value)
child = @path.join(key)
if value
child.binwrite Marshal.dump(value)
elsif child.exist?
child.unlink
end
end
|
#each_key ⇒ Object
269
270
271
272
273
|
# File 'lib/gel/db.rb', line 269
def each_key
@path.each_child(false) do |child|
yield child.to_s
end
end
|
#key?(key) ⇒ Boolean
275
276
277
|
# File 'lib/gel/db.rb', line 275
def key?(key)
@path.join(key).exist?
end
|
#reading ⇒ Object
265
266
267
|
# File 'lib/gel/db.rb', line 265
def reading
yield
end
|
#writing ⇒ Object
260
261
262
263
|
# File 'lib/gel/db.rb', line 260
def writing
@path.mkdir unless @path.exist?
yield
end
|