Module: Mongoid::State::InstanceMethods

Defined in:
lib/mongoid/state.rb

Instance Method Summary collapse

Instance Method Details

#destroyed=(destroyed) ⇒ Object

Sets the destroyed boolean - used after document is destroyed.



34
35
36
# File 'lib/mongoid/state.rb', line 34

def destroyed=(destroyed)
  @destroyed = destroyed && true
end

#destroyed?Boolean

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.

Returns:



29
30
31
# File 'lib/mongoid/state.rb', line 29

def destroyed?
  @destroyed == true
end

#new_record=(saved) ⇒ Object

Sets the new_record boolean - used after document is saved.



18
19
20
# File 'lib/mongoid/state.rb', line 18

def new_record=(saved)
  @new_record = saved
end

#new_record?Boolean

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.

Returns:



13
14
15
# File 'lib/mongoid/state.rb', line 13

def new_record?
  !!@new_record
end

#persisted?Boolean

Checks if the document has been saved to the database.

Returns:



23
24
25
# File 'lib/mongoid/state.rb', line 23

def persisted?
  !new_record?
end