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.



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

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

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



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

def adapter
  @adapter
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#clause(delta_source = false) ⇒ Object



10
11
12
13
14
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 10

def clause(delta_source = false)
  return nil unless delta_source

  "#{adapter.quoted_table_name}.#{quoted_column} = #{adapter.boolean_value delta_source}"
end

#delete(index, instance) ⇒ Object



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

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

#index(index) ⇒ Object



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

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

#reset_queryObject



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

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



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

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

#toggled?(instance) ⇒ Boolean

Returns:

  • (Boolean)


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

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