Class: AlgoliaSearch::SafeIndex
- Inherits:
-
Object
- Object
- AlgoliaSearch::SafeIndex
- Defined in:
- lib/algoliasearch-rails.rb
Overview
this class wraps an Algolia::Index object ensuring all raised exceptions are correctly logged or thrown depending on the ‘raise_on_failure` option
Class Method Summary collapse
-
.move_index(old_name, new_name) ⇒ Object
expose move as well.
Instance Method Summary collapse
-
#get_settings(*args) ⇒ Object
special handling of get_settings to avoid raising errors on 404.
-
#initialize(name, raise_on_failure) ⇒ SafeIndex
constructor
A new instance of SafeIndex.
-
#wait_task(task_id) ⇒ Object
special handling of wait_task to handle null task_id.
Constructor Details
#initialize(name, raise_on_failure) ⇒ SafeIndex
Returns a new instance of SafeIndex.
306 307 308 309 |
# File 'lib/algoliasearch-rails.rb', line 306 def initialize(name, raise_on_failure) @index = ::Algolia::Index.new(name) @raise_on_failure = raise_on_failure.nil? || raise_on_failure end |
Class Method Details
.move_index(old_name, new_name) ⇒ Object
expose move as well
340 341 342 343 344 |
# File 'lib/algoliasearch-rails.rb', line 340 def self.move_index(old_name, new_name) SafeIndex.log_or_throw(:move_index, true) do ::Algolia.move_index(old_name, new_name) end end |
Instance Method Details
#get_settings(*args) ⇒ Object
special handling of get_settings to avoid raising errors on 404
328 329 330 331 332 333 334 335 336 337 |
# File 'lib/algoliasearch-rails.rb', line 328 def get_settings(*args) SafeIndex.log_or_throw(:get_settings, @raise_on_failure) do begin @index.get_settings(*args) rescue Algolia::AlgoliaError => e return {} if e.code == 404 # not fatal raise e end end end |
#wait_task(task_id) ⇒ Object
special handling of wait_task to handle null task_id
320 321 322 323 324 325 |
# File 'lib/algoliasearch-rails.rb', line 320 def wait_task(task_id) return if task_id.nil? && !@raise_on_failure # ok SafeIndex.log_or_throw(:wait_task, @raise_on_failure) do @index.wait_task(task_id) end end |