Sha256: 9e2166f72b33ce6dedf23173688e726dc22188045becf136b8a5118acfaf91c5

Contents?: true

Size: 1.42 KB

Versions: 9

Compression:

Stored size: 1.42 KB

Contents

module Sunspot #:nodoc:
  module Rails #:nodoc:
    # 
    # 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.
    #
    module RequestLifecycle
      class <<self
        def included(base) #:nodoc:
          subclasses = base.subclasses.map do |subclass|
            begin
              subclass.constantize
            rescue NameError
            end
          end.compact
          loaded_controllers = [base].concat(subclasses)
          # 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.
          callback = ::Rails::VERSION::MAJOR > 3 ? :after_action : :after_filter

          loaded_controllers.each do |controller|
            controller.send(callback) 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
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
sunspot_rails-2.7.1 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.7.0 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.6.0 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.5.0 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.4.0 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.3.0 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.2.8 lib/sunspot/rails/request_lifecycle.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot_rails-2.2.7/lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.2.7 lib/sunspot/rails/request_lifecycle.rb