module Sunspot::SubmodelIndex
Public Class Methods
included(klass)
click to toggle source
# File lib/sunspot_submodel_index/submodel_index.rb, line 4 def self.included(klass) klass.class_eval do # Solr Index a parent model when this model is saved or destroyed. # # ==== Options (+options+) # # :parent<Symbol>:: # Method to call to access the parent to Solr index. # :if<Proc>:: # A Proc that is called before the parent index and is passed an instance of the object. # Will block Solr index of the parent if false is returned. # :force_association_reload<Boolean>:: # Force a reload on the parent association for Solr index is called on the parent. # :include_attributes<Array>:: # Define only those attributes whose change should trigger a reindex of the parent. # :ignore_attributes<Array>:: # Define attributes, that should not trigger a reindex of the parent. # # ==== Example # # class Company < ActiveRecord::Base # has_many :people # sunspot_submodel_index :parent => :people, :included_attributes => [:name] # end # def self.sunspot_submodel_index(options = {}) include Sunspot::SubmodelIndex::InstanceMethods extend Sunspot::SubmodelIndex::ClassMethods class_attribute :_sunspot_submodel_options options[:parent] = options[:parent].to_sym options[:included_attributes] = false if options[:included_attributes].blank? #set to false if empty sent options[:ignored_attributes] = false if options[:ignored_attributes].blank? #set to false if empty sent options[:force_association_reload] = false if options[:force_association_reload].blank? #set to false if empty sent self._sunspot_submodel_options = options #add call backs before_save :mark_for_parent_solr_index after_save :parent_solr_index after_destroy :parent_solr_index_on_destroy end end end
sunspot_submodel_index(options = {})
click to toggle source
Solr Index a parent model when this model is saved or destroyed.
Options (options
)¶ ↑
- :parent<Symbol>
-
Method to call to access the parent to Solr index.
- :if<Proc>
-
A Proc that is called before the parent index and is passed an instance of the object. Will block Solr index of the parent if false is returned.
- :force_association_reload<Boolean>
-
Force a reload on the parent association for Solr index is called on the parent.
- :include_attributes<Array>
-
Define only those attributes whose change should trigger a reindex of the parent.
- :ignore_attributes<Array>
-
Define attributes, that should not trigger a reindex of the parent.
Example¶ ↑
class Company < ActiveRecord::Base has_many :people sunspot_submodel_index :parent => :people, :included_attributes => [:name] end
# File lib/sunspot_submodel_index/submodel_index.rb, line 30 def self.sunspot_submodel_index(options = {}) include Sunspot::SubmodelIndex::InstanceMethods extend Sunspot::SubmodelIndex::ClassMethods class_attribute :_sunspot_submodel_options options[:parent] = options[:parent].to_sym options[:included_attributes] = false if options[:included_attributes].blank? #set to false if empty sent options[:ignored_attributes] = false if options[:ignored_attributes].blank? #set to false if empty sent options[:force_association_reload] = false if options[:force_association_reload].blank? #set to false if empty sent self._sunspot_submodel_options = options #add call backs before_save :mark_for_parent_solr_index after_save :parent_solr_index after_destroy :parent_solr_index_on_destroy end