Sha256: e0f449a57ecb785aed1f44c9794ad650e763b59ddceed20348095bcc79b70632

Contents?: true

Size: 1.66 KB

Versions: 52

Compression:

Stored size: 1.66 KB

Contents

module Sunspot
  module SessionProxy
    # 
    # An abstract subclass of ShardingSessionProxy that shards by class.
    # Concrete subclasses should not override the #session_for method, but
    # should instead implement the #session_for_class method. They must also
    # still implement the #all_sessions method.
    #
    # Unlike its parent class, ClassShardingSessionProxy implements
    # #remove_by_id and all flavors of #remove_all.
    #
    class ClassShardingSessionProxy < ShardingSessionProxy
      # 
      # Remove the Session object pointing at the shard that indexes the given
      # class.
      #
      # <strong>Concrete subclasses must implement this method.</strong>
      #
      def session_for_class(clazz)
        raise NotImplementedError
      end

      # 
      # See Sunspot.remove_by_id
      #
      def remove_by_id(clazz, id)
        session_for_class(clazz).remove_by_id(clazz, id)
      end

      # 
      # See Sunspot.remove_by_id!
      #
      def remove_by_id!(clazz, id)
        session_for_class(clazz).remove_by_id!(clazz, id)
      end

      # 
      # See Sunspot.remove_all
      #
      def remove_all(clazz = nil)
        if clazz
          session_for_class(clazz).remove_all(clazz)
        else
          all_sessions.each { |session| session.remove_all }
        end
      end

      # 
      # See Sunspot.remove_all!
      #
      def remove_all!(clazz = nil)
        if clazz
          session_for_class(clazz).remove_all!(clazz)
        else
          all_sessions.each { |session| session.remove_all! }
        end
      end

      private

      def session_for(object)
        session_for_class(object.class)
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 11 rubygems

Version Path
sunspot-2.1.0 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.0.0 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.0.0.pre.130115 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
gojee-sunspot-2.0.5 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.0.0.pre.120925 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot_solr-2.0.0.pre.120924 sunspot/lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot_rails-2.0.0.pre.120924 sunspot/lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.0.0.pre.120924 sunspot/lib/sunspot/session_proxy/class_sharding_session_proxy.rb
gojee-sunspot-2.0.4 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
gojee-sunspot-2.0.2 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.0.0.pre.120720 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-1.3.3 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-1.3.2 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.0.0.pre.120417 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.0.0.pre.120415 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-1.3.1 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
erichummel-sunspot-2.0.0.pre.111215d lib/sunspot/session_proxy/class_sharding_session_proxy.rb
erichummel-sunspot-2.0.0.pre.111215c lib/sunspot/session_proxy/class_sharding_session_proxy.rb
erichummel-sunspot-2.0.0.pre.111215b lib/sunspot/session_proxy/class_sharding_session_proxy.rb
erichummel-sunspot-2.0.0.pre.111215a lib/sunspot/session_proxy/class_sharding_session_proxy.rb