Module: Mongoid::Stateful
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
| Included In: | |
| Defined in: | lib/mongoid/stateful.rb | 
Overview
Mixin module included into Document which adds behavior for getting the various lifecycle states a document can transition through.
Instance Attribute Summary
- 
    
      #_destroy  
    
    readonly
    Alias for #flagged_for_destroy?. 
- #destroyed=(value) rw
- 
    
      #destroyed?  ⇒ true | false 
    
    rw
    Returns true if the Documenthas been successfully destroyed, and false if it hasn’t.
- #flagged_for_destroy=(value) rw
- 
    
      #flagged_for_destroy?  ⇒ true | false 
      (also: #marked_for_destruction?, #_destroy)
    
    rw
    Returns whether or not the document has been flagged for deletion, but not destroyed yet. 
- 
    
      #marked_for_destruction?  
    
    readonly
    Alias for #flagged_for_destroy?. 
- 
    
      #new_record=(new_value)  ⇒ true | false 
    
    rw
    Sets whether the document has been persisted to the database. 
- 
    
      #new_record?  ⇒ true | false 
    
    rw
    Returns true if the document has not been persisted to the database, false if it has. 
- 
    
      #persisted?  ⇒ true | false 
    
    readonly
    Checks if the document has been saved to the database. 
- #previously_new_record=(value) rw
- 
    
      #previously_new_record?  ⇒ true | false 
    
    rw
    Returns true if this document was just created – that is, prior to the last save, the object didn’t exist in the database and new_record? would have returned true. 
- 
    
      #previously_persisted?  ⇒ true | false 
    
    readonly
    Checks if the document was previously saved to the database but now it has been deleted. 
- 
    
      #pushable?  ⇒ true | false 
    
    readonly
    Determine if the document can be pushed. 
- 
    
      #readonly?  ⇒ true | false 
    
    readonly
    Is the document readonly? 
- 
    
      #settable?  ⇒ true | false 
    
    readonly
    Determine if the document can be set. 
- 
    
      #updateable?  ⇒ true | false 
    
    readonly
    Is the document updateable? 
Instance Method Summary
- 
    
      #readonly!  ⇒ true | false 
    
    Flags the document as readonly. 
- #reset_readonly private
Instance Attribute Details
#_destroy (readonly)
Alias for #flagged_for_destroy?.
# File 'lib/mongoid/stateful.rb', line 77
alias :_destroy :flagged_for_destroy?
#destroyed=(value) (rw)
[ GitHub ]# File 'lib/mongoid/stateful.rb', line 10
attr_writer :destroyed, :flagged_for_destroy, :previously_new_record
    #destroyed?  ⇒ true | false  (rw)
  
Returns true if the Document has been successfully destroyed, and false if it hasn’t. This is determined by the variable @destroyed and NOT by checking the database.
# File 'lib/mongoid/stateful.rb', line 87
def destroyed? @destroyed ||= false end
#flagged_for_destroy=(value) (rw)
[ GitHub ]# File 'lib/mongoid/stateful.rb', line 10
attr_writer :destroyed, :flagged_for_destroy, :previously_new_record
    #flagged_for_destroy?  ⇒ true | false  (rw)
    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.
# File 'lib/mongoid/stateful.rb', line 73
def flagged_for_destroy? @flagged_for_destroy ||= false end
#marked_for_destruction? (readonly)
Alias for #flagged_for_destroy?.
# File 'lib/mongoid/stateful.rb', line 76
alias :marked_for_destruction? :flagged_for_destroy?
    #new_record=(new_value)  ⇒ true | false  (rw)
  
Sets whether the document has been persisted to the database.
# File 'lib/mongoid/stateful.rb', line 17
def new_record=(new_value) @new_record ||= false if @new_record && !new_value @previously_new_record = true end @new_record = new_value end
    #new_record?  ⇒ true | false  (rw)
  
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.
# File 'lib/mongoid/stateful.rb', line 33
def new_record? @new_record ||= false end
    #persisted?  ⇒ true | false  (readonly)
  
Checks if the document has been saved to the database. Returns false if the document has been destroyed.
# File 'lib/mongoid/stateful.rb', line 53
def persisted? !new_record? && !destroyed? end
#previously_new_record=(value) (rw)
[ GitHub ]# File 'lib/mongoid/stateful.rb', line 10
attr_writer :destroyed, :flagged_for_destroy, :previously_new_record
    #previously_new_record?  ⇒ true | false  (rw)
  
Returns true if this document was just created – that is, prior to the last save, the object didn’t exist in the database and new_record? would have returned true.
# File 'lib/mongoid/stateful.rb', line 42
def previously_new_record? @previously_new_record ||= false end
    #previously_persisted?  ⇒ true | false  (readonly)
  
Checks if the document was previously saved to the database but now it has been deleted.
# File 'lib/mongoid/stateful.rb', line 62
def previously_persisted? !new_record? && destroyed? end
    #pushable?  ⇒ true | false  (readonly)
  
Determine if the document can be pushed.
# File 'lib/mongoid/stateful.rb', line 97
def pushable? new_record? && && _parent.persisted? && !_parent.delayed_atomic_sets[atomic_path] end
    #readonly?  ⇒ true | false  (readonly)
  
Is the document readonly?
# File 'lib/mongoid/stateful.rb', line 127
def readonly? if Mongoid.legacy_readonly __selected_fields != nil else @readonly ||= false end end
    #settable?  ⇒ true | false  (readonly)
  
Determine if the document can be set.
# File 'lib/mongoid/stateful.rb', line 141
def settable? new_record? && && _parent.persisted? end
    #updateable?  ⇒ true | false  (readonly)
  
Is the document updateable?
# File 'lib/mongoid/stateful.rb', line 151
def updateable? persisted? && changed? end
Instance Method Details
    #readonly!  ⇒ true | false 
  
Flags the document as readonly. Will cause a ReadonlyDocument error to be raised if the document is attempted to be saved, updated or destroyed.
#reset_readonly (private)
[ GitHub ]# File 'lib/mongoid/stateful.rb', line 157
def reset_readonly self.__selected_fields = nil end