Sha256: 610bf1c9f1d4424082a477833999949bc8b7fcc60abf885cb299d1ecfc82a644

Contents?: true

Size: 1.1 KB

Versions: 33

Compression:

Stored size: 1.1 KB

Contents

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

      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>
      Operations::READ.each do |name|
        define_method(name) { |*args| collection.send(name, *args) }
      end

      # 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

33 entries across 33 versions & 7 rubygems

Version Path
mongoid-2.0.0.beta.14 lib/mongoid/collections/slaves.rb
mongoid-2.0.0.beta.13 lib/mongoid/collections/slaves.rb
mongoid-2.0.0.beta.11 lib/mongoid/collections/slaves.rb
mongoid-2.0.0.beta.10 lib/mongoid/collections/slaves.rb
mongoid-2.0.0.beta.7 lib/mongoid/collections/slaves.rb
mongoid-2.0.0.beta.8 lib/mongoid/collections/slaves.rb
mongoid-2.0.0.beta.9 lib/mongoid/collections/slaves.rb
mongoid-2.0.0.beta.12 lib/mongoid/collections/slaves.rb
mongoid-locomotive-2.0.0.beta9 lib/mongoid/collections/slaves.rb
mongoid-1.9.1 lib/mongoid/collections/slaves.rb
chhean-mongoid-2.0.1.beta1 lib/mongoid/collections/slaves.rb
mongoid-2.0.0.beta.5 lib/mongoid/collections/slaves.rb
mongoid-1.9.0 lib/mongoid/collections/slaves.rb