Sha256: a7a91bf9aa74416bf6b0369e7c51cb132ad49609a5f39a4a72aad61467cc3dfc

Contents?: true

Size: 1.14 KB

Versions: 15

Compression:

Stored size: 1.14 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Persistence #:nodoc:
    # Persistence commands extend from this class to get basic functionality on
    # initialization.
    class Command
      attr_reader \
        :collection,
        :document,
        :klass,
        :options,
        :selector,
        :validate

      # Initialize the persistence +Command+.
      #
      # Options:
      #
      # document_or_class: The +Document+ or +Class+ to get the collection.
      # validate: Is the document to be validated.
      # selector: Optional selector to use in query.
      #
      # Example:
      #
      # <tt>DeleteAll.new(Person, false, {})</tt>
      def initialize(document_or_class, validate = true, selector = {})
        if document_or_class.is_a?(Mongoid::Document)
          @document = document_or_class
          @collection = @document.embedded? ? @document._root.collection : @document.collection
        else
          @klass = document_or_class
          @collection = @klass.collection
        end
        @selector, @validate = selector, validate
        @options = { :safe => Mongoid.persist_in_safe_mode }
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 6 rubygems

Version Path
mongoid-1.9.5 lib/mongoid/persistence/command.rb
mongoid-with-auth-1.9.4 lib/mongoid/persistence/command.rb
mongoid-rails2-1.9.4 lib/mongoid/persistence/command.rb
mongoid-rails2-1.9.3 lib/mongoid/persistence/command.rb
mongoid-1.9.2 lib/mongoid/persistence/command.rb
sskirby-mongoid-1.9.1 lib/mongoid/persistence/command.rb
mongoid-2.0.0.beta.10 lib/mongoid/persistence/command.rb
mongoid-2.0.0.beta.7 lib/mongoid/persistence/command.rb
mongoid-2.0.0.beta.8 lib/mongoid/persistence/command.rb
mongoid-2.0.0.beta.9 lib/mongoid/persistence/command.rb
mongoid-locomotive-2.0.0.beta9 lib/mongoid/persistence/command.rb
mongoid-1.9.1 lib/mongoid/persistence/command.rb
chhean-mongoid-2.0.1.beta1 lib/mongoid/persistence/command.rb
mongoid-2.0.0.beta.5 lib/mongoid/persistence/command.rb
mongoid-1.9.0 lib/mongoid/persistence/command.rb