Sha256: 15d0c53ae2e9d6c8b6f78bc5474d6e4da64871e17f4477926e5404802aad739a

Contents?: true

Size: 853 Bytes

Versions: 6

Compression:

Stored size: 853 Bytes

Contents

# frozen_string_literal: true

require 'rake'
require 'pg_search'

namespace :pg_search do
  namespace :multisearch do
    desc "Rebuild PgSearch multisearch records for a given model"
    task :rebuild, %i[model schema] => :environment do |_task, args|
      raise ArgumentError, <<-MESSAGE.strip_heredoc unless args.model

        You must pass a model as an argument.
        Example: rake pg_search:multisearch:rebuild[BlogPost]
      MESSAGE
      model_class = args.model.classify.constantize
      connection = PgSearch::Document.connection
      original_schema_search_path = connection.schema_search_path
      begin
        connection.schema_search_path = args.schema if args.schema
        PgSearch::Multisearch.rebuild(model_class)
      ensure
        connection.schema_search_path = original_schema_search_path
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pg_search-2.3.0 lib/pg_search/tasks.rb
pg_search-2.2.0 lib/pg_search/tasks.rb
pg_search-2.1.7 lib/pg_search/tasks.rb
pg_search-2.1.6 lib/pg_search/tasks.rb
pg_search-2.1.5 lib/pg_search/tasks.rb
pg_search-2.1.4 lib/pg_search/tasks.rb