Method: PEROBS::Store#each

Defined in:
lib/perobs/Store.rb

#eachObject

Calls the given block once for each object, passing that object as a parameter.



485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'lib/perobs/Store.rb', line 485

def each
  @lock.synchronize do
    @db.clear_marks
    # Start with the object 0 and the indexes of the root objects. Push them
    # onto the work stack.
    stack = [ 0 ] + @root_objects.values
    while !stack.empty?
      # Get an object index from the stack.
      id = stack.pop
      next if @db.is_marked?(id)

      unless (obj = object_by_id_internal(id))
        PEROBS.log.fatal "Database is corrupted. Object with ID #{id} " +
          "not found."
      end
      # Mark the object so it will never be pushed to the stack again.
      @db.mark(id)
      yield(obj.myself) if block_given?
      # Push the IDs of all unmarked referenced objects onto the stack
      obj._referenced_object_ids.each do |r_id|
        stack << r_id unless @db.is_marked?(r_id)
      end
    end
  end
end