lib/daybreak/db.rb in daybreak-0.0.1 vs lib/daybreak/db.rb in daybreak-0.0.2
- old
+ new
@@ -9,11 +9,12 @@
# to store when accessing a previously unset key, this follows the
# Hash standard.
# @param [String] file the path to the db file
# @param default the default value to store and return when a key is
# not yet in the database.
- # @yield [key] blk a block that will return the default value to store.
+ # @yield [key] a block that will return the default value to store.
+ # @yieldparam [String] key the key to be stored.
def initialize(file, default=nil, &blk)
@file_name = file
reset!
@default = default
@default = blk if block_given?
@@ -58,20 +59,24 @@
end
end
alias_method :get, :"[]"
# Iterate over the key, value pairs in the database.
+ # @yield [key, value] blk the iterator for each key value pair.
+ # @yieldparam [String] key the key.
+ # @yieldparam value the value from the database.
def each(&blk)
keys.each { |k| blk.call(k, get(k)) }
end
# Does this db have a default value.
def default?
!@default.nil?
end
# Does this db have a value for this key?
+ # @param [key#to_s] key the key to check if the DB has a key.
def has_key?(key)
@table.has_key? key.to_s
end
# Return the keys in the db.
@@ -102,11 +107,11 @@
Marshal.load(value)
end
# Reset and empty the database file.
def empty!
- reset!
@writer.truncate!
+ reset!
end
# Force all queued commits to be written to disk.
def flush!
@writer.flush!