Sha256: 4e0df7ac74093560fb9420f6acc2cef46bcda5a42e47a5899b1b8eb22506e539

Contents?: true

Size: 681 Bytes

Versions: 4

Compression:

Stored size: 681 Bytes

Contents

require "active_support/concern"
require "active_support/core_ext/class/attribute"

module PgSearch
  module Multisearchable
    extend ActiveSupport::Concern

    included do
      has_one :pg_search_document,
        :as => :searchable,
        :class_name => "PgSearch::Document",
        :dependent => :delete

      after_create :create_pg_search_document,
        :if => lambda { PgSearch.multisearch_enabled? }

      after_update :update_pg_search_document,
        :if => lambda { PgSearch.multisearch_enabled? }
    end

    def update_pg_search_document
      create_pg_search_document unless self.pg_search_document
      self.pg_search_document.save
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pg_search-0.5.1 lib/pg_search/multisearchable.rb
pg_search-0.5 lib/pg_search/multisearchable.rb
pg_search-0.4.2 lib/pg_search/multisearchable.rb
pg_search-0.4.1 lib/pg_search/multisearchable.rb