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(adapter, options = {})



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

def initialize(adapter, options = {})
  @adapter, @options = adapter, options
end

Instance Attribute Details

- (Object) adapter (readonly)

Returns the value of attribute adapter



2
3
4
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 2

def adapter
  @adapter
end

- (Object) options (readonly)

Returns the value of attribute options



2
3
4
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 2

def options
  @options
end

Instance Method Details

- (Object) clause(delta_source = false)



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

def clause(delta_source = false)
  "#{adapter.quoted_table_name}.#{quoted_column} = #{adapter.boolean_value delta_source}"
end

- (Object) delete(index, instance)



12
13
14
15
16
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 12

def delete(index, instance)
  ThinkingSphinx::Deltas::DeleteJob.new(
    index.name, index.document_id_for_key(instance.id)
  ).perform
end

- (Object) index(index)



18
19
20
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 18

def index(index)
  ThinkingSphinx::Deltas::IndexJob.new(index.name).perform
end

- (Object) reset_query



22
23
24
25
26
27
28
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 22

def reset_query
  (<<-SQL).strip.gsub(/\n\s*/, ' ')
UPDATE #{adapter.quoted_table_name}
SET #{quoted_column} = #{adapter.boolean_value false}
WHERE #{quoted_column} = #{adapter.boolean_value true}
  SQL
end

- (Object) toggle(instance)



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

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

- (Boolean) toggled?(instance)



34
35
36
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 34

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