Module: Tripod::State
Overview
This module contains the behaviour for getting the various states through which a resource can transition.
Instance Attribute Summary collapse
-
#destroyed ⇒ Object
writeonly
Sets the attribute destroyed.
-
#new_record ⇒ Object
writeonly
Sets the attribute new_record.
Instance Method Summary collapse
-
#destroyed? ⇒ true, false
(also: #deleted?)
Returns true if the
Resource
has been succesfully destroyed, and false if it hasn’t. -
#new_record? ⇒ true, false
Returns true if the
Resource
has not been persisted to the database, false if it has. -
#persisted? ⇒ true, false
Checks if the resource has been saved to the database.
Instance Attribute Details
#destroyed=(value) ⇒ Object (writeonly)
Sets the attribute destroyed
9 10 11 |
# File 'lib/tripod/state.rb', line 9 def destroyed=(value) @destroyed = value end |
#new_record=(value) ⇒ Object (writeonly)
Sets the attribute new_record
9 10 11 |
# File 'lib/tripod/state.rb', line 9 def new_record=(value) @new_record = value end |
Instance Method Details
#destroyed? ⇒ true, false Also known as: deleted?
Returns true if the Resource
has been succesfully destroyed, and false if it hasn’t. This is determined by the variable @destroyed and NOT by checking the database.
42 43 44 |
# File 'lib/tripod/state.rb', line 42 def destroyed? @destroyed ||= false end |
#new_record? ⇒ true, false
Returns true if the Resource
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.
19 20 21 |
# File 'lib/tripod/state.rb', line 19 def new_record? @new_record ||= false end |
#persisted? ⇒ true, false
Checks if the resource has been saved to the database. Returns false if the resource has been destroyed.
30 31 32 |
# File 'lib/tripod/state.rb', line 30 def persisted? !new_record? && !destroyed? end |