Class: ThinkingSphinx::Deltas::DefaultDelta
- Inherits:
-
Object
- Object
- ThinkingSphinx::Deltas::DefaultDelta
- Defined in:
- lib/thinking_sphinx/deltas/default_delta.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
Returns the value of attribute column.
Instance Method Summary collapse
- #clause(model, toggled) ⇒ Object
- #index(model, instance = nil) ⇒ Object
-
#initialize(index, options) ⇒ DefaultDelta
constructor
A new instance of DefaultDelta.
- #reset_query(model) ⇒ Object
- #toggle(instance) ⇒ Object
- #toggled(instance) ⇒ Object
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, ) @index = index @column = .delete(:delta_column) || :delta end |
Instance Attribute Details
#column ⇒ Object
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
46 47 48 49 |
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 46 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 21 22 23 24 25 26 27 28 29 30 |
# 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) config = ThinkingSphinx::Configuration.instance client = Riddle::Client.new config.address, config.port rotate = ThinkingSphinx.sphinx_running? ? "--rotate" : "" output = `#{config.bin_path}#{config.indexer_binary_name} --config #{config.config_file} #{rotate} #{delta_index_name model}` puts(output) unless ThinkingSphinx.suppress_delta_output? client.update( core_index_name(model), ['sphinx_deleted'], {instance.sphinx_document_id => [1]} ) if instance && ThinkingSphinx.sphinx_running? && instance.in_both_indexes? true end |
#reset_query(model) ⇒ Object
40 41 42 43 44 |
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 40 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
32 33 34 |
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 32 def toggle(instance) instance.delta = true end |
#toggled(instance) ⇒ Object
36 37 38 |
# File 'lib/thinking_sphinx/deltas/default_delta.rb', line 36 def toggled(instance) instance.delta end |