def update
      unless File.exist? @config_filepath
        raise "cannot update catalog #{@name}"
      end
      read_config
      #
      # migrate db
      #
      DataMapper.auto_migrate!
      #DataMapper.auto_upgrade!

      #
      # Initialize categories
      #
      if @config[:categories]
        # pp @config[:categories]
        @config[:categories].each_pair do |category, tags|
          # puts category
          cat = Category.first_or_create(:name => category)
          tags.each do |name|
            tag = Tag.first_or_create(:name => name)
            tag.category = cat
            tag.save
          end
        end
      end

      #
      # read catalog root
      #
      @config[:roots].each do |root|
        dtw = TreeVisitor::DirTreeWalker.new(root)
        dtw.ignore /^\./
        @config[:ignore].each do |i|
          dtw.ignore i
        end
        dtw.visit_file=true
        dtw.run(DirectoryVisitor.new(root))
      end

      #
      # cache rating tag
      #
      rating = Category.first(:name => "rating")
      if rating
        Item.all.each do |item|
          t = item.tags.find { |t| t.category == rating }
          if t
            item.rating = t.name.to_i
            item.save
          end
        end
      end
    end
def update
      unless File.exist? @config_filepath
        raise "cannot update catalog #{@name}"
      end
      read_config
      #
      # migrate db
      #
      DataMapper.auto_migrate!
      #DataMapper.auto_upgrade!

      #
      # Initialize categories
      #
      if @config[:categories]
        # pp @config[:categories]
        @config[:categories].each_pair do |category, tags|
          # puts category
          cat = Category.first_or_create(:name => category)
          tags.each do |name|
            tag = Tag.first_or_create(:name => name)
            tag.category = cat
            tag.save
          end
        end
      end

      #
      # read catalog root
      #
      @config[:roots].each do |root|
        dtw = TreeVisitor::DirTreeWalker.new(root)
        dtw.ignore /^\./
        @config[:ignore].each do |i|
          dtw.ignore i
        end
        dtw.visit_file=true
        dtw.run(DirectoryVisitor.new(root))
      end

      #
      # cache rating tag
      #
      rating = Category.first(:name => "rating")
      if rating
        Item.all.each do |item|
          t = item.tags.find { |t| t.category == rating }
          if t
            item.rating = t.name.to_i
            item.save
          end
        end
      end
    end
Rebuild catalog