Sha256: fdbb64925ad696fbea16f66aa75991b7f26a619c8bd7ffd734932507406e2f5f

Contents?: true

Size: 1.34 KB

Versions: 49

Compression:

Stored size: 1.34 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.
          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
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 10 rubygems

Version Path
sunspot_rails-2.2.6 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.2.5 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.2.4 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.2.3 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.2.2 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.2.1 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.2.0 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.1.1 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.1.0 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.0.0 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.0.0.pre.130115 lib/sunspot/rails/request_lifecycle.rb
substantial-sunspot_rails-2.0.0.pre.111215 lib/sunspot/rails/request_lifecycle.rb
gojee-sunspot-rails-2.0.5 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.0.0.pre.120925 lib/sunspot/rails/request_lifecycle.rb
sunspot_solr-2.0.0.pre.120924 sunspot_rails/lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.0.0.pre.120924 sunspot_rails/lib/sunspot/rails/request_lifecycle.rb
sunspot-2.0.0.pre.120924 sunspot_rails/lib/sunspot/rails/request_lifecycle.rb
gojee-sunspot-rails-2.0.4 lib/sunspot/rails/request_lifecycle.rb
gojee-sunspot-rails-2.0.2 lib/sunspot/rails/request_lifecycle.rb
sunspot_rails-2.0.0.pre.120720 lib/sunspot/rails/request_lifecycle.rb