Class: ThinkingSphinx::Deltas::DefaultDelta

Inherits:
Object
  • Object
show all
Defined in:
lib/thinking_sphinx/deltas/default_delta.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, options) ⇒ DefaultDelta

Returns a new instance of DefaultDelta.



6
7
8
9
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 6

def initialize(index, options)
  @index  = index
  @column = options.delete(:delta_column) || :delta
end

Instance Attribute Details

#columnObject

Returns the value of attribute column.



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

def column
  @column
end

Instance Method Details

#clause(model, toggled) ⇒ Object



36
37
38
39
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 36

def clause(model, toggled)
  "#{model.quoted_table_name}.#{model.connection.quote_column_name(@column.to_s)}" +
  " = #{adapter.boolean(toggled)}"
end

#index(model, instance = nil) ⇒ Object



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

def index(model, instance = nil)
  return true unless ThinkingSphinx.updates_enabled? &&
    ThinkingSphinx.deltas_enabled?
  return true if instance && !toggled(instance)
  
  update_delta_indexes model
  delete_from_core     model, instance if instance
  
  true
end

#reset_query(model) ⇒ Object



30
31
32
33
34
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 30

def reset_query(model)
  "UPDATE #{model.quoted_table_name} SET " +
  "#{model.connection.quote_column_name(@column.to_s)} = #{adapter.boolean(false)} " +
  "WHERE #{model.connection.quote_column_name(@column.to_s)} = #{adapter.boolean(true)}"
end

#toggle(instance) ⇒ Object



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

def toggle(instance)
  instance.delta = true
end

#toggled(instance) ⇒ Object



26
27
28
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 26

def toggled(instance)
  instance.delta
end