Module: Sunspot::SubmodelIndex::InstanceMethods
- Defined in:
- lib/sunspot_submodel_index/submodel_index.rb
Instance Method Summary collapse
- #call_parent_solr_index ⇒ Object
- #check_parent_solr_if_statement ⇒ Object
-
#mark_for_parent_solr_index ⇒ Object
to run before a save to see if this is a new record, or if fields I care about changed.
-
#parent_solr_index ⇒ Object
call reindex if I need too.
-
#parent_solr_index_on_destroy ⇒ Object
always call reindex on destroy.
Instance Method Details
#call_parent_solr_index ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/sunspot_submodel_index/submodel_index.rb', line 54 def call_parent_solr_index if self.respond_to?(self.[:parent]) && !self.send(self.[:parent]).nil? self.send(self.[:parent],true) if self.[:force_association_reload] if self.send(self.[:parent]).is_a?(Enumerable) self.send(self.[:parent]).each {|item| item.solr_index } else self.send(self.[:parent]).solr_index end end end |
#check_parent_solr_if_statement ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/sunspot_submodel_index/submodel_index.rb', line 65 def check_parent_solr_if_statement if self.[:if] && self.[:if].instance_of?(Proc) self.[:if].call(self) else true end end |
#mark_for_parent_solr_index ⇒ Object
to run before a save to see if this is a new record, or if fields I care about changed.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sunspot_submodel_index/submodel_index.rb', line 74 def mark_for_parent_solr_index #only mark for index if the record is new, or if fields changed that I care about #check the if proc first return unless check_parent_solr_if_statement if self.[:included_attributes] fields_changed = !(self.changed.map {|k| k.to_sym} & self.[:included_attributes]).empty? elsif self.[:ignored_attributes] fields_changed = !(self.changed.map {|k| k.to_sym} - self.[:ignored_attributes]).empty? else fields_changed = true end if new_record? || fields_changed @marked_for_parent_solr_indexing = true end end |
#parent_solr_index ⇒ Object
call reindex if I need too
91 92 93 94 95 96 |
# File 'lib/sunspot_submodel_index/submodel_index.rb', line 91 def parent_solr_index if @marked_for_parent_solr_indexing call_parent_solr_index remove_instance_variable(:@marked_for_parent_solr_indexing) end end |
#parent_solr_index_on_destroy ⇒ Object
always call reindex on destroy
99 100 101 102 |
# File 'lib/sunspot_submodel_index/submodel_index.rb', line 99 def parent_solr_index_on_destroy return unless check_parent_solr_if_statement call_parent_solr_index end |