Sha256: 33c60d8b4d94c5459256a3bb0cd70401e0aa9e885759e86ff6b3fb981c1f16d4

Contents?: true

Size: 1.71 KB

Versions: 17

Compression:

Stored size: 1.71 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, *ids)
        ids.flatten!
        session_for_class(clazz).remove_by_id(clazz, ids)
      end

      # 
      # See Sunspot.remove_by_id!
      #
      def remove_by_id!(clazz, *ids)
        ids.flatten!
        session_for_class(clazz).remove_by_id!(clazz, ids)
      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

17 entries across 17 versions & 2 rubygems

Version Path
sunspot-2.7.1 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.7.0 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.6.0 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.5.0 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.4.0 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.3.0 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.2.8 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.2.7 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.2.6 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.2.5 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.2.4 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.2.3 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.2.2 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.2.1 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.2.0 lib/sunspot/session_proxy/class_sharding_session_proxy.rb
sunspot-2.1.1 lib/sunspot/session_proxy/class_sharding_session_proxy.rb