Module: Sunspot::Rails::RequestLifecycle
- Defined in:
- lib/sunspot/rails/request_lifecycle.rb
Overview
This module adds an after_filter to ActionController::Base that commits the Sunspot session if any documents have been added, changed, or removed in the course of the request.
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Class Method Details
.included(base) ⇒ Object
:nodoc:
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sunspot/rails/request_lifecycle.rb', line 10 def included(base) #:nodoc: loaded_controllers = [base].concat(base.subclasses.map { |subclass| subclass.constantize }) # Depending on how Sunspot::Rails is loaded, there may already be # controllers loaded into memory that subclass this controller. In # this case, since after_filter uses the inheritable_attribute # structure, the already-loaded subclasses don't get the filters. So, # the below ensures that all loaded controllers have the filter. loaded_controllers.each do |controller| controller.after_filter do if Sunspot::Rails.configuration.auto_commit_after_request? Sunspot.commit_if_dirty elsif Sunspot::Rails.configuration.auto_commit_after_delete_request? Sunspot.commit_if_delete_dirty end end end end |