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

- (DefaultDelta) initialize(index, options)

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

- (Object) column

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

- (Object) clause(model, toggled)



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

- (Object) index(model, instance = nil)



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

- (Object) reset_query(model)



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

- (Object) toggle(instance)



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

def toggle(instance)
  instance.send "#{@column}=", true
end

- (Object) toggled(instance)



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

def toggled(instance)
  instance.send "#{@column}"
end