Module: ActsAsFulltextable::FulltextableInstanceMethods
- Defined in:
- lib/acts_as_fulltextable.rb
Instance Method Summary collapse
-
#create_fulltext_record ⇒ Object
Creates the fulltext_row record for self.
-
#fulltext_value ⇒ Object
Returns self’s value created by concatenating fulltext fields for its class.
-
#parent_id_value ⇒ Object
Returns the parent_id value or nil if it wasn’t set.
-
#update_fulltext_record ⇒ Object
Updates self’s fulltext_row record.
Instance Method Details
#create_fulltext_record ⇒ Object
Creates the fulltext_row record for self
67 68 69 |
# File 'lib/acts_as_fulltextable.rb', line 67 def create_fulltext_record FulltextRow.create(:fulltextable_type => self.class.to_s, :fulltextable_id => self.id, :value => self.fulltext_value, :parent_id => self.parent_id_value) if eval self.class.[:conditions] end |
#fulltext_value ⇒ Object
Returns self’s value created by concatenating fulltext fields for its class
99 100 101 102 |
# File 'lib/acts_as_fulltextable.rb', line 99 def fulltext_value full_value = self.class.fulltext_fields.map {|f| self.send(f)}.join("\n") full_value end |
#parent_id_value ⇒ Object
Returns the parent_id value or nil if it wasn’t set.
73 74 75 |
# File 'lib/acts_as_fulltextable.rb', line 73 def parent_id_value self.class.[:parent_id].nil? ? nil : self.send(self.class.[:parent_id]) end |
#update_fulltext_record ⇒ Object
Updates self’s fulltext_row record
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/acts_as_fulltextable.rb', line 79 def update_fulltext_record if eval self.class.[:conditions] if self.class.[:check_for_changes] row = FulltextRow.find_by_fulltextable_type_and_fulltextable_id(self.class.to_s, self.id) # If we haven't got a row for the record, yet, create it instead of updating it. if row.nil? self.create_fulltext_record return end end FulltextRow.update_all(["value = ?, parent_id = ?", self.fulltext_value, self.parent_id_value], ["fulltextable_type = ? AND fulltextable_id = ?", self.class.to_s, self.id]) if !(self.class.[:check_for_changes]) || (row.value != self.fulltext_value) || (self.parent_id_value != row.parent_id) else row = FulltextRow.find_by_fulltextable_type_and_fulltextable_id(self.class.to_s, self.id) row.destroy unless row.nil? end end |