Sha256: 54f2e0b1375c4c4b00326beb9f882e99b11b70f35d088acd0a1138b3b9203d42

Contents?: true

Size: 897 Bytes

Versions: 4

Compression:

Stored size: 897 Bytes

Contents

class ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks
  def initialize(reference, path = [])
    @reference, @path = reference, path
  end

  def after_save(instance)
    return unless real_time_indices?

    real_time_indices.each do |index|
      objects_for(instance).each do |object|
        ThinkingSphinx::RealTime::Transcriber.new(index).copy object
      end
    end
  end

  private

  attr_reader :reference, :path

  def configuration
    ThinkingSphinx::Configuration.instance
  end

  def indices
    @indices ||= configuration.indices_for_references reference
  end

  def objects_for(instance)
    Array(path.inject(instance) { |object, method| object.send method })
  end

  def real_time_indices?
    real_time_indices.any?
  end

  def real_time_indices
    @real_time_indices ||= indices.select { |index|
      index.is_a? ThinkingSphinx::RealTime::Index
    }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
thinking-sphinx-3.1.0 lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb
thinking-sphinx-3.0.6 lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb
thinking-sphinx-3.0.5 lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb
thinking-sphinx-3.0.4 lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb