Module: Mongoid::Stateful
- Included in:
- Composable
- Defined in:
- build/mongoid-6.1/lib/mongoid/stateful.rb
Overview
This module contains the behaviour for getting the various states a document can transition through.
Instance Attribute Summary collapse
-
#destroyed ⇒ Object
writeonly
Sets the attribute destroyed.
-
#flagged_for_destroy ⇒ Object
writeonly
Sets the attribute flagged_for_destroy.
-
#new_record ⇒ Object
writeonly
Sets the attribute new_record.
Instance Method Summary collapse
-
#destroyed? ⇒ true, false
Returns true if the
Document
has been succesfully destroyed, and false if it hasn’t. -
#flagged_for_destroy? ⇒ true, false
(also: #marked_for_destruction?, #_destroy)
Returns whether or not the document has been flagged for deletion, but not destroyed yet.
-
#new_record? ⇒ true, false
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.
-
#pushable? ⇒ true, false
Determine if the document can be pushed.
-
#readonly? ⇒ true, false
Is the document readonly?.
-
#settable? ⇒ true, false
Determine if the document can be set.
-
#updateable? ⇒ true, false
Is the document updateable?.
Instance Attribute Details
#destroyed=(value) ⇒ Object (writeonly)
Sets the attribute destroyed
8 9 10 |
# File 'build/mongoid-6.1/lib/mongoid/stateful.rb', line 8 def destroyed=(value) @destroyed = value end |
#flagged_for_destroy=(value) ⇒ Object (writeonly)
Sets the attribute flagged_for_destroy
8 9 10 |
# File 'build/mongoid-6.1/lib/mongoid/stateful.rb', line 8 def flagged_for_destroy=(value) @flagged_for_destroy = value end |
#new_record=(value) ⇒ Object (writeonly)
Sets the attribute new_record
8 9 10 |
# File 'build/mongoid-6.1/lib/mongoid/stateful.rb', line 8 def new_record=(value) @new_record = value end |
Instance Method Details
#destroyed? ⇒ true, false
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.
56 57 58 |
# File 'build/mongoid-6.1/lib/mongoid/stateful.rb', line 56 def destroyed? @destroyed ||= false end |
#flagged_for_destroy? ⇒ true, false Also known as: marked_for_destruction?, _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 'build/mongoid-6.1/lib/mongoid/stateful.rb', line 42 def flagged_for_destroy? @flagged_for_destroy ||= false end |
#new_record? ⇒ true, false
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 'build/mongoid-6.1/lib/mongoid/stateful.rb', line 18 def new_record? @new_record ||= false end |
#persisted? ⇒ true, false
Checks if the document has been saved to the database. Returns false if the document has been destroyed.
29 30 31 |
# File 'build/mongoid-6.1/lib/mongoid/stateful.rb', line 29 def persisted? !new_record? && !destroyed? end |
#pushable? ⇒ true, false
Determine if the document can be pushed.
66 67 68 69 70 71 |
# File 'build/mongoid-6.1/lib/mongoid/stateful.rb', line 66 def pushable? new_record? && && _parent.persisted? && !_parent.delayed_atomic_sets[atomic_path] end |
#readonly? ⇒ true, false
Is the document readonly?
81 82 83 |
# File 'build/mongoid-6.1/lib/mongoid/stateful.rb', line 81 def readonly? __selected_fields != nil end |
#settable? ⇒ true, false
Determine if the document can be set.
93 94 95 |
# File 'build/mongoid-6.1/lib/mongoid/stateful.rb', line 93 def settable? new_record? && && _parent.persisted? end |
#updateable? ⇒ true, false
Is the document updateable?
105 106 107 |
# File 'build/mongoid-6.1/lib/mongoid/stateful.rb', line 105 def updateable? persisted? && changed? end |