Class: Searchkick::RecordIndexer
- Inherits:
-
Object
- Object
- Searchkick::RecordIndexer
- Defined in:
- lib/searchkick/record_indexer.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
-
#initialize(record) ⇒ RecordIndexer
constructor
A new instance of RecordIndexer.
- #reindex(method_name = nil, refresh: false, mode: nil) ⇒ Object
Constructor Details
#initialize(record) ⇒ RecordIndexer
Returns a new instance of RecordIndexer.
5 6 7 8 |
# File 'lib/searchkick/record_indexer.rb', line 5 def initialize(record) @record = record @index = record.class.searchkick_index end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
3 4 5 |
# File 'lib/searchkick/record_indexer.rb', line 3 def index @index end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
3 4 5 |
# File 'lib/searchkick/record_indexer.rb', line 3 def record @record end |
Instance Method Details
#reindex(method_name = nil, refresh: false, mode: nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/searchkick/record_indexer.rb', line 10 def reindex(method_name = nil, refresh: false, mode: nil) unless [true, nil, :async, :queue].include?(mode) raise ArgumentError, "Invalid value for mode" end mode ||= Searchkick.callbacks_value || index.[:callbacks] || true case mode when :queue if method_name raise Searchkick::Error, "Partial reindex not supported with queue option" end index.reindex_queue.push(record.id.to_s) when :async unless defined?(ActiveJob) raise Searchkick::Error, "Active Job not found" end Searchkick::ReindexV2Job.perform_later( record.class.name, record.id.to_s, method_name ? method_name.to_s : nil ) else # bulk, true reindex_record(method_name) index.refresh if refresh end end |