Sha256: a86ffb3978b18329163fc05b3d0d4ef7eeeceebf42a3338640c9f1f9777a3c0f

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

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

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

  def clause(delta_source = false)
    return nil unless delta_source

    "#{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

7 entries across 7 versions & 1 rubygems

Version Path
thinking-sphinx-3.3.0 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-3.2.0 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-3.1.4 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-3.1.3 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-3.1.2 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-3.1.1 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-3.1.0 lib/thinking_sphinx/deltas/default_delta.rb