Class: Mongoid::Persistence::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/persistence/command.rb

Overview

Persistence commands extend from this class to get basic functionality on initialization.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document_or_class, validate = true, selector = {}) ⇒ Command

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:

DeleteAll.new(Person, false, {})



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mongoid/persistence/command.rb', line 26

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

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



7
8
9
# File 'lib/mongoid/persistence/command.rb', line 7

def collection
  @collection
end

#documentObject (readonly)

Returns the value of attribute document.



7
8
9
# File 'lib/mongoid/persistence/command.rb', line 7

def document
  @document
end

#klassObject (readonly)

Returns the value of attribute klass.



7
8
9
# File 'lib/mongoid/persistence/command.rb', line 7

def klass
  @klass
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/mongoid/persistence/command.rb', line 7

def options
  @options
end

#selectorObject (readonly)

Returns the value of attribute selector.



7
8
9
# File 'lib/mongoid/persistence/command.rb', line 7

def selector
  @selector
end

#validateObject (readonly)

Returns the value of attribute validate.



7
8
9
# File 'lib/mongoid/persistence/command.rb', line 7

def validate
  @validate
end