| Class | YamlStore |
| In: |
lib/storage/yamlstore.rb
|
| Parent: | Store |
The YamlStore class manages access to all object storage.
# File lib/storage/yamlstore.rb, line 27 def initialize(dbfile) super() @dbfile = "#{dbfile}.yaml" # check if database exists and build it if not build_database log.info "Loading world..." @db = {} # load the yaml database and sets @dbtop to highest object id YAML::load_file(@dbfile).each do |o| @dbtop = o.id if o.id > @dbtop @db[o.id]=o end log.info "Database '#{@dbfile}' loaded...highest id = #{@dbtop}." # log.debug @db.inspect rescue log.fatal "Error loading database" log.fatal $! raise end
Check if an object is in the database by its id.
# File lib/storage/yamlstore.rb, line 83 def check(oid) @db.has_key? oid end
Deletes an object from the database.
# File lib/storage/yamlstore.rb, line 69 def delete(oid) @db.delete(oid) end
Iterate through all objects
# File lib/storage/yamlstore.rb, line 89 def each(&blk) @db.each_value &blk end
Finds an object in the database by its id.
# File lib/storage/yamlstore.rb, line 76 def get(oid) @db[oid] end