Sha256: 00318a4d8cbbb1979034af6837cf4a8eef7f638a74a6bf426e3f2ac2d563a571

Contents?: true

Size: 1.05 KB

Versions: 18

Compression:

Stored size: 1.05 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Collections #:nodoc:
    class Slaves
      include Mimic

      attr_reader :iterator

      # All read operations should delegate to the slave connections.
      # These operations mimic the methods on a Mongo:Collection.
      #
      # Example:
      #
      # <tt>collection.save({ :name => "Al" })</tt>
      proxy(:collection, Operations::READ)

      # Is the collection of slaves empty or not?
      #
      # Return:
      #
      # True is the iterator is not set, false if not.
      def empty?
        @iterator.nil?
      end

      # Create the new database reader. Will create a collection from the
      # slave databases and cycle through them on each read.
      #
      # Example:
      #
      # <tt>Reader.new(slaves, "mongoid_people")</tt>
      def initialize(slaves, name)
        unless slaves.blank?
          @iterator = CyclicIterator.new(slaves.collect { |db| db.collection(name) })
        end
      end

      protected
      def collection
        @iterator.next
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
mongoid-pre-2.0.0.beta1 lib/mongoid/collections/slaves.rb
mongoid-2.0.0.alpha lib/mongoid/collections/slaves.rb
mongoid-1.2.14 lib/mongoid/collections/slaves.rb
mongoid-1.2.13 lib/mongoid/collections/slaves.rb
mongoid-1.2.12 lib/mongoid/collections/slaves.rb
mongoid-1.2.11 lib/mongoid/collections/slaves.rb
mongoid-1.2.10 lib/mongoid/collections/slaves.rb
mongoid-1.2.9 lib/mongoid/collections/slaves.rb
mongoid-1.2.8 lib/mongoid/collections/slaves.rb
mongoid-1.2.7 lib/mongoid/collections/slaves.rb
mongoid-pre-2.0.0.pre lib/mongoid/collections/slaves.rb
mongoid-1.2.6 lib/mongoid/collections/slaves.rb
mongoid-1.2.5 lib/mongoid/collections/slaves.rb
mongoid-1.2.4 lib/mongoid/collections/slaves.rb
mongoid-1.2.3 lib/mongoid/collections/slaves.rb
mongoid-1.2.2 lib/mongoid/collections/slaves.rb
mongoid-1.2.1 lib/mongoid/collections/slaves.rb
mongoid-1.2.0 lib/mongoid/collections/slaves.rb