Sha256: f2bdc1624cf51d0812581cdadddc4fa367875c939a129767e49df6bce79ef9e4

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
  ThinkingSphinx::Callbacks

  callbacks :after_commit, :before_save

  def after_commit
    return unless delta_indices? && processors.any? { |processor|
      processor.toggled?(instance)
    } && !ThinkingSphinx::Deltas.suspended?

    delta_indices.each do |index|
      index.delta_processor.index index
    end

    core_indices.each do |index|
      index.delta_processor.delete index, instance
    end
  end

  def before_save
    return unless delta_indices?

    processors.each { |processor| processor.toggle instance }
  end

  private

  def config
    ThinkingSphinx::Configuration.instance
  end

  def core_indices
    @core_indices ||= indices.reject { |index| index.delta? }
  end

  def delta_indices
    @delta_indices ||= indices.select { |index| index.delta? }
  end

  def delta_indices?
    delta_indices.any?
  end

  def indices
    @indices ||= ThinkingSphinx::IndexSet.new [instance.class], []
  end

  def processors
    delta_indices.collect &:delta_processor
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
thinking-sphinx-3.0.6 lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb
thinking-sphinx-3.0.5 lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb
thinking-sphinx-3.0.4 lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb
thinking-sphinx-3.0.3 lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb
thinking-sphinx-3.0.2 lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb
thinking-sphinx-3.0.1 lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb