Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord_reindex/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inherited(child) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/activerecord_reindex/base.rb', line 13

def self.inherited(child)
  super
  class << child

    attr_accessor :reindexer, :async_adapter, :sync_adapter, :sync_reindexable_reflections,
                  :async_reindexable_reflections, :reindex_attr_blacklist, :reindex_attr_whitelist

  end

  # Init default values to prevent undefined method for nilClass error
  child.sync_reindexable_reflections = []
  child.async_reindexable_reflections = []

  child.reindexer = ActiverecordReindex::Reindexer.new
  # TODO: provide config for changing adapters
  # For now can set adapter through writers inside class
  if ActiverecordReindex.config.async_reindex_only_in_production? && !Rails.env.production?
    child.async_adapter = ActiverecordReindex::SyncAdapter
  else
    child.async_adapter = ActiverecordReindex::AsyncAdapter
  end

  child.sync_adapter = ActiverecordReindex::SyncAdapter
end

Instance Method Details

#reindex_async(reflection, skip_record: nil) ⇒ Object



38
39
40
# File 'lib/activerecord_reindex/base.rb', line 38

def reindex_async(reflection, skip_record: nil)
  _reindex(reflection, strategy: self.class.async_adapter, skip_record: skip_record)
end

#reindex_sync(reflection, skip_record: nil) ⇒ Object



42
43
44
# File 'lib/activerecord_reindex/base.rb', line 42

def reindex_sync(reflection, skip_record: nil)
  _reindex(reflection, strategy: self.class.sync_adapter, skip_record: skip_record)
end