Class: Mongoid::Persistence::Command
- Defined in:
- lib/mongoid/persistence/command.rb
Overview
Persistence commands extend from this class to get basic functionality on initialization.
Direct Known Subclasses
Insert, InsertEmbedded, Remove, RemoveAll, RemoveEmbedded, Update
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#selector ⇒ Object
readonly
Returns the value of attribute selector.
-
#validate ⇒ Object
readonly
Returns the value of attribute validate.
Instance Method Summary collapse
-
#initialize(document_or_class, validate = true, selector = {}) ⇒ Command
constructor
Initialize the persistence
Command
.
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. ? @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
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
7 8 9 |
# File 'lib/mongoid/persistence/command.rb', line 7 def collection @collection end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
7 8 9 |
# File 'lib/mongoid/persistence/command.rb', line 7 def document @document end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
7 8 9 |
# File 'lib/mongoid/persistence/command.rb', line 7 def klass @klass end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/mongoid/persistence/command.rb', line 7 def @options end |
#selector ⇒ Object (readonly)
Returns the value of attribute selector.
7 8 9 |
# File 'lib/mongoid/persistence/command.rb', line 7 def selector @selector end |
#validate ⇒ Object (readonly)
Returns the value of attribute validate.
7 8 9 |
# File 'lib/mongoid/persistence/command.rb', line 7 def validate @validate end |