Sha256: 29cdd6ca31a8cf6191c784c691b36cf4cbbdb2bb94325bdeb66b796342b425bd

Contents?: true

Size: 821 Bytes

Versions: 2

Compression:

Stored size: 821 Bytes

Contents

require 'ruby-progressbar'

module Pose
  module Jobs

    # Recreates the Pose search index for the given class from scratch.
    class ReindexAll
      attr_reader :klass

      # @param [String, Class] clazz
      def initialize(clazz)
        @klass = case clazz
                   when String
                     clazz.constantize
                   when Class
                     clazz
                   else
                     raise ArgumentError, "Class or String expected, #{clazz.class} given"
                 end
      end

      def perform
        progress_bar = ProgressBar.create title: "  reindexing", total: klass.count

        klass.find_each do |instance|
          instance.update_pose_words
          progress_bar.increment
        end

        progress_bar.finish
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pose-3.2.0 lib/pose/jobs/reindex_all.rb
pose-3.1.1 lib/pose/jobs/reindex_all.rb