Module: Tripod::State

Extended by:
ActiveSupport::Concern
Included in:
Components
Defined in:
lib/tripod/state.rb

Overview

This module contains the behaviour for getting the various states through which a resource can transition.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#destroyed=(value) ⇒ Object (writeonly)

Sets the attribute destroyed

Parameters:

  • value

    the value to set the attribute destroyed to.



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

Parameters:

  • value

    the value to set the attribute new_record to.



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.

Examples:

Is the resource destroyed?

person.destroyed?

Returns:

  • (true, false)

    True if destroyed, false if not.



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.

Examples:

Is the resource new?

person.new_record?

Returns:

  • (true, false)

    True if new, false if not.



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.

Examples:

Is the resource persisted?

person.persisted?

Returns:

  • (true, false)

    True if persisted, false if not.



30
31
32
# File 'lib/tripod/state.rb', line 30

def persisted?
  !new_record? && !destroyed?
end