Sha256: f5ba7232f9682915a7bac7f33aa4fd859c194417b65e91108251b9330bbd5df0

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

include Rake::DSL if defined?(Rake::DSL)
require 'progressbar'
namespace :pose do

  namespace :index do

    desc "Cleans out unused data from the search index."
    task :vacuum => :environment do |t, args|
      puts "Cleaning Pose search index ...\n\n"
      progress_bar = ProgressBar.new '  assignments', PoseAssignment.count
      PoseAssignment.cleanup_orphaned_pose_assignments progress_bar
      progress_bar.finish

      progress_bar = ProgressBar.new '  words', PoseWord.count
      PoseWord.remove_unused_words progress_bar
      progress_bar.finish

      puts "\nPose search index cleanup complete.\n\n"
    end

    desc "Removes the search index for all instances of the given classes."
    task :remove, [:class_name] => :environment do |t, args|
      clazz = Kernel.const_get args.class_name
      PoseAssignment.cleanup_class_index clazz
      puts "Search index for class #{clazz.name} deleted.\n\n"
    end

    desc "Deletes and recreates the search index for all instances of the given class."
    task :reindex_all, [:class_name] => [:environment] do |t, args|
      clazz = Kernel.const_get args.class_name
      progress_bar = ProgressBar.new "  reindexing", clazz.count
      clazz.find_each do |instance|
        instance.update_pose_words
        progress_bar.inc
      end
      progress_bar.finish
    end
    
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pose-1.3.1 lib/tasks/pose_tasks.rake
pose-1.3 lib/tasks/pose_tasks.rake
pose-1.2.5 lib/tasks/pose_tasks.rake
pose-1.2.4 lib/tasks/pose_tasks.rake