Sha256: 91297fb6b5b252283a64418d745378facd43066e16802fd81951f4b8e930c646

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 KB

Contents

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

    # This class wraps the MongoDB master database.
    class Master
      include Mongoid::Collections::Retry

      attr_reader :collection

      # All read and write operations should delegate to the master connection.
      # These operations mimic the methods on a Mongo:Collection.
      #
      # @example Proxy the driver save.
      #   collection.save({ :name => "Al" })
      Operations::ALL.each do |name|
        class_eval <<-EOS, __FILE__, __LINE__
          def #{name}(*args)
            retry_on_connection_failure do
              collection.#{name}(*args)
            end
          end
        EOS
      end

      # Create the new database writer. Will create a collection from the
      # master database.
      #
      # @example Create a new wrapped master.
      #   Master.new(db, "testing")
      #
      # @param [ Mongo::DB ] master The master database.
      # @param [ String ] name The name of the database.
      def initialize(master, name)
        @collection = master.collection(name)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mongoid-2.1.9 lib/mongoid/collections/master.rb
mongoid-2.1.8 lib/mongoid/collections/master.rb
mongoid-2.1.7 lib/mongoid/collections/master.rb
mongoid-2.1.6 lib/mongoid/collections/master.rb
mongoid-2.1.5 lib/mongoid/collections/master.rb
mongoid-2.1.4 lib/mongoid/collections/master.rb
mongoid-2.1.3 lib/mongoid/collections/master.rb
mongoid-2.1.2 lib/mongoid/collections/master.rb
mongoid-2.1.1 lib/mongoid/collections/master.rb
mongoid-2.1.0 lib/mongoid/collections/master.rb