Sha256: 30925da0e5d7214e7c1f584df0667e8c0fb9a2a0d221f497d3bc85f12ecfef8e

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

class ThinkingSphinx::Callbacks::Appender
  def self.call(model, reference, options, &block)
    new(model, reference, options, &block).call
  end

  def initialize(model, reference, options, &block)
    @model = model
    @reference = reference
    @options = options
    @block = block
  end

  def call
    model.after_destroy ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks

    if behaviours.include?(:deltas)
      model.before_save  ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
      model.after_commit ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
    end

    if behaviours.include?(:real_time)
      model.after_save ThinkingSphinx::RealTime.callback_for(
        reference, path, &block
      )
    end

    if behaviours.include?(:updates)
      model.after_update(
        ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks
      )
    end
  end

  private

  attr_reader :model, :reference, :options, :block

  def behaviours
    options[:behaviours] || []
  end

  def path
    options[:path] || []
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinking-sphinx-5.0.0 lib/thinking_sphinx/callbacks/appender.rb