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

Returns a new instance of DefaultDelta



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

#adapterObject (readonly)

Returns the value of attribute adapter



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

def adapter
  @adapter
end

#optionsObject (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

#clause(delta_source = false) ⇒ Object



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

#delete(index, instance) ⇒ Object



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

#index(index) ⇒ Object



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

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

#reset_queryObject



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

#toggle(instance) ⇒ Object



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

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

#toggled?(instance) ⇒ Boolean

Returns:

  • (Boolean)


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

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