class ThinkingSphinx::Callbacks::Appender

Attributes

block[R]
model[R]
options[R]
reference[R]

Public Class Methods

call(model, reference, options, &block) click to toggle source
# File lib/thinking_sphinx/callbacks/appender.rb, line 4
def self.call(model, reference, options, &block)
  new(model, reference, options, &block).call
end
new(model, reference, options, &block) click to toggle source
# File lib/thinking_sphinx/callbacks/appender.rb, line 8
def initialize(model, reference, options, &block)
  @model = model
  @reference = reference
  @options = options
  @block = block
end

Public Instance Methods

call() click to toggle source
# File lib/thinking_sphinx/callbacks/appender.rb, line 15
def call
  add_core_callbacks
  add_delta_callbacks     if behaviours.include?(:deltas)
  add_real_time_callbacks if behaviours.include?(:real_time)
  add_update_callbacks    if behaviours.include?(:updates)
end

Private Instance Methods

add_core_callbacks() click to toggle source
# File lib/thinking_sphinx/callbacks/appender.rb, line 26
def add_core_callbacks
  model.after_commit(
    ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks,
    on: :destroy
  )
end
add_delta_callbacks() click to toggle source
# File lib/thinking_sphinx/callbacks/appender.rb, line 33
def add_delta_callbacks
  if path.empty?
    model.before_save  ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
    model.after_commit ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
  else
    model.after_commit(
      ThinkingSphinx::ActiveRecord::Callbacks::AssociationDeltaCallbacks
        .new(path)
    )
  end
end
add_real_time_callbacks() click to toggle source
# File lib/thinking_sphinx/callbacks/appender.rb, line 45
def add_real_time_callbacks
  model.after_commit(
    ThinkingSphinx::RealTime.callback_for(reference, path, &block),
    on: [:create, :update]
  )
end
add_update_callbacks() click to toggle source
# File lib/thinking_sphinx/callbacks/appender.rb, line 52
def add_update_callbacks
  model.after_update ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks
end
behaviours() click to toggle source
# File lib/thinking_sphinx/callbacks/appender.rb, line 56
def behaviours
  options[:behaviours] || []
end
path() click to toggle source
# File lib/thinking_sphinx/callbacks/appender.rb, line 60
def path
  options[:path] || []
end