Class: MySQL::Search::Updater
- Inherits:
-
Object
- Object
- MySQL::Search::Updater
- Defined in:
- lib/mysql/search/updater.rb
Overview
Updates search indices based on associated models.
Instance Attribute Summary collapse
-
#associated_model ⇒ Object
readonly
Returns the value of attribute associated_model.
-
#full_text_searchable ⇒ Object
readonly
Returns the value of attribute full_text_searchable.
-
#joins_args ⇒ Object
readonly
Returns the value of attribute joins_args.
-
#source_class ⇒ Object
readonly
Returns the value of attribute source_class.
Instance Method Summary collapse
-
#initialize(full_text_searchable:, associated_model:, association_path: []) ⇒ Updater
constructor
A new instance of Updater.
- #update ⇒ Object
Constructor Details
#initialize(full_text_searchable:, associated_model:, association_path: []) ⇒ Updater
Returns a new instance of Updater.
12 13 14 15 16 17 |
# File 'lib/mysql/search/updater.rb', line 12 def initialize(full_text_searchable:, associated_model:, association_path: []) @full_text_searchable = full_text_searchable @associated_model = associated_model @joins_args = translate_to_joins_args(association_path) @source_class = "#{full_text_searchable.name}Source".constantize end |
Instance Attribute Details
#associated_model ⇒ Object (readonly)
Returns the value of attribute associated_model.
7 8 9 |
# File 'lib/mysql/search/updater.rb', line 7 def associated_model @associated_model end |
#full_text_searchable ⇒ Object (readonly)
Returns the value of attribute full_text_searchable.
7 8 9 |
# File 'lib/mysql/search/updater.rb', line 7 def full_text_searchable @full_text_searchable end |
#joins_args ⇒ Object (readonly)
Returns the value of attribute joins_args.
7 8 9 |
# File 'lib/mysql/search/updater.rb', line 7 def joins_args @joins_args end |
#source_class ⇒ Object (readonly)
Returns the value of attribute source_class.
7 8 9 |
# File 'lib/mysql/search/updater.rb', line 7 def source_class @source_class end |
Instance Method Details
#update ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/mysql/search/updater.rb', line 19 def update full_text_searchable.transaction do full_text_searchables.find_each do |model| search_index = model.search_index || model.build_search_index search_index.update(source_class.new(model).extract) end end end |