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 Method Summary collapse
-
#destroyed=(destroyed) ⇒ true, false
Sets the destroyed boolean - used after document is destroyed.
-
#destroyed? ⇒ true, false
(also: #deleted?)
Returns true if the
Document
has been succesfully destroyed, and false if it hasn’t. -
#new_record=(saved) ⇒ true, false
Sets the new_record boolean - used after document is saved.
-
#new_record? ⇒ true, false
(also: #new?)
Returns true if the
Document
has not been persisted to the database, false if it has. -
#persisted? ⇒ true, false
Checks if the document has been saved to the database.
Instance Method Details
#destroyed=(destroyed) ⇒ true, false
Sets the destroyed boolean - used after document is destroyed.
63 64 65 |
# File 'lib/mongoid/state.rb', line 63 def destroyed=(destroyed) @destroyed = destroyed && true end |
#destroyed? ⇒ true, false 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.
52 53 54 |
# File 'lib/mongoid/state.rb', line 52 def destroyed? @destroyed == true end |
#new_record=(saved) ⇒ true, false
Sets the new_record boolean - used after document is saved.
29 30 31 |
# File 'lib/mongoid/state.rb', line 29 def new_record=(saved) @new_record = saved end |
#new_record? ⇒ true, false Also known as: new?
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.
16 17 18 |
# File 'lib/mongoid/state.rb', line 16 def new_record? @new_record == true end |
#persisted? ⇒ true, false
Checks if the document has been saved to the database. Returns false if the document has been destroyed.
40 41 42 |
# File 'lib/mongoid/state.rb', line 40 def persisted? !new_record? && !destroyed? end |