Module: Mongoid::State
- Included in:
- Components
- Defined in:
- lib/mongoid/state.rb
Overview
This module contains the behaviour for getting the various states a document can transition through.
Instance Attribute Summary (collapse)
-
- (Object) destroyed
writeonly
Sets the attribute destroyed.
-
- (Object) flagged_for_destroy
writeonly
Sets the attribute flagged_for_destroy.
-
- (Object) new_record
writeonly
Sets the attribute new_record.
Instance Method Summary (collapse)
-
- (true, false) destroyed?
(also: #deleted?)
Returns true if the Document has been succesfully destroyed, and false if it hasn't.
-
- (true, false) flagged_for_destroy?
Returns whether or not the document has been flagged for deletion, but not destroyed yet.
-
- (true, false) new_record?
Returns true if the Document has not been persisted to the database, false if it has.
-
- (true, false) persisted?
Checks if the document has been saved to the database.
-
- (true, false) pushable?
Determine if the document can be pushed.
-
- (true, false) settable?
Determine if the document can be set.
-
- (true, false) updateable?
Is the document updateable?.
Instance Attribute Details
- (Object) destroyed=(value) (writeonly)
Sets the attribute destroyed
8 9 10 |
# File 'lib/mongoid/state.rb', line 8 def destroyed=(value) @destroyed = value end |
- (Object) flagged_for_destroy=(value) (writeonly)
Sets the attribute flagged_for_destroy
8 9 10 |
# File 'lib/mongoid/state.rb', line 8 def flagged_for_destroy=(value) @flagged_for_destroy = value end |
- (Object) new_record=(value) (writeonly)
Sets the attribute new_record
8 9 10 |
# File 'lib/mongoid/state.rb', line 8 def new_record=(value) @new_record = value end |
Instance Method Details
- (true, false) destroyed? Also known as: deleted?
Returns true if the Document has been succesfully destroyed, and false if it hasn't. This is determined by the variable @destroyed and NOT by checking the database.
54 55 56 |
# File 'lib/mongoid/state.rb', line 54 def destroyed? @destroyed ||= false end |
- (true, false) flagged_for_destroy?
Returns whether or not the document has been flagged for deletion, but not destroyed yet. Used for atomic pulls of child documents.
42 43 44 |
# File 'lib/mongoid/state.rb', line 42 def flagged_for_destroy? @flagged_for_destroy ||= false end |
- (true, false) new_record?
Returns true if the Document has not been persisted to the database, false if it has. This is determined by the variable @new_record and NOT if the object has an id.
18 19 20 |
# File 'lib/mongoid/state.rb', line 18 def new_record? @new_record ||= false end |
- (true, false) persisted?
Checks if the document has been saved to the database. Returns false if the document has been destroyed.
29 30 31 |
# File 'lib/mongoid/state.rb', line 29 def persisted? !new_record? && !destroyed? end |
- (true, false) pushable?
Determine if the document can be pushed.
65 66 67 68 69 70 |
# File 'lib/mongoid/state.rb', line 65 def pushable? new_record? && && _parent.persisted? && !_parent.delayed_atomic_sets[atomic_path] end |
- (true, false) settable?
Determine if the document can be set.
80 81 82 |
# File 'lib/mongoid/state.rb', line 80 def settable? new_record? && && _parent.persisted? end |
- (true, false) updateable?
Is the document updateable?
92 93 94 |
# File 'lib/mongoid/state.rb', line 92 def updateable? persisted? && changed? end |