Module: ThinkingSphinx::Deltas

Defined in:
lib/thinking_sphinx/deltas.rb

Defined Under Namespace

Classes: DefaultDelta, DeleteJob, IndexJob

Class Method Summary collapse

Class Method Details

.configObject



4
5
6
# File 'lib/thinking_sphinx/deltas.rb', line 4

def self.config
  ThinkingSphinx::Configuration.instance
end

.processor_for(delta) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/thinking_sphinx/deltas.rb', line 8

def self.processor_for(delta)
  case delta
  when TrueClass
    ThinkingSphinx::Deltas::DefaultDelta
  when Class
    delta
  when String
    delta.constantize
  else
    nil
  end
end

.resume!Object



21
22
23
# File 'lib/thinking_sphinx/deltas.rb', line 21

def self.resume!
  @suspended = false
end

.suspend(reference, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/thinking_sphinx/deltas.rb', line 25

def self.suspend(reference, &block)
  suspend!
  yield
  resume!

  config.indices_for_references(reference).each do |index|
    index.delta_processor.index index if index.delta?
  end
end

.suspend!Object



44
45
46
# File 'lib/thinking_sphinx/deltas.rb', line 44

def self.suspend!
  @suspended = true
end

.suspend_and_update(reference, &block) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/thinking_sphinx/deltas.rb', line 35

def self.suspend_and_update(reference, &block)
  suspend reference, &block

  ids = reference.to_s.camelize.constantize.where(delta: true).pluck(:id)
  config.indices_for_references(reference).each do |index|
    ThinkingSphinx::Deletion.perform index, ids unless index.delta?
  end
end

.suspended?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/thinking_sphinx/deltas.rb', line 48

def self.suspended?
  @suspended
end