class ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks

Public Instance Methods

after_update() click to toggle source
# File lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb, line 6
def after_update
  return unless updates_enabled?

  indices.each do |index|
    update index unless index.distributed?
  end
end

Private Instance Methods

attributes_hash_for(index) click to toggle source
# File lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb, line 16
def attributes_hash_for(index)
  updateable_attributes_for(index).inject({}) do |hash, attribute|
    if instance.changed.include?(attribute.columns.first.__name.to_s)
      hash[attribute.name] = attribute.value_for(instance)
    end

    hash
  end
end
configuration() click to toggle source
# File lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb, line 26
def configuration
  ThinkingSphinx::Configuration.instance
end
indices() click to toggle source
# File lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb, line 30
def indices
  @indices ||= begin
    all = configuration.indices_for_references(reference)
    all.reject { |index| index.type == 'rt' }
  end
end
reference() click to toggle source
# File lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb, line 37
def reference
  instance.class.name.underscore.to_sym
end
update(index) click to toggle source
# File lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb, line 41
def update(index)
  attributes = attributes_hash_for(index)
  return if attributes.empty?

  sphinxql = Riddle::Query.update(
    index.name, index.document_id_for_key(instance.id), attributes
  )
  ThinkingSphinx::Connection.take do |connection|
    connection.execute(sphinxql)
  end
rescue ThinkingSphinx::ConnectionError => error
  # This isn't vital, so don't raise the error.
end
updateable_attributes_for(index) click to toggle source
# File lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb, line 55
def updateable_attributes_for(index)
  index.sources.collect(&:attributes).flatten.select { |attribute|
    attribute.updateable?
  }
end
updates_enabled?() click to toggle source
# File lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb, line 61
def updates_enabled?
  configuration.settings['attribute_updates']
end