Sha256: d300795ab5b2a274540932a47440d207796b7d6e0cdba40328959ac69d92bba9

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

class ThinkingSphinx::Deltas::DefaultDelta
  attr_reader :adapter, :options

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

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

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

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

  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

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

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

  private

  def column
    options[:column] || :delta
  end

  def config
    ThinkingSphinx::Configuration.instance
  end

  def controller
    config.controller
  end

  def quoted_column
    adapter.quote column
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
thinking-sphinx-3.0.6 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-3.0.5 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-3.0.4 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-3.0.3 lib/thinking_sphinx/deltas/default_delta.rb