Skip to content

Reko States

Thomas Starzynski edited this page May 28, 2019 · 3 revisions

Reko States

  • The model Reko has an integer field called state, which can have 3 different values:
    • open (default)
    • done
    • rejected
  • in the database, state is encoded as an integer mapped to the three values provided. The encoding is as follows (0: open, 1: done, 2: rejected)
  • the default value is 0 (= open)
  • in the ruby world, Active Record provides us with methods that enhance readibility of the code. (see code snippet below)
  • more info here

Methods build in by rails!

# CREATE NEW REKO
reko = Reko.new # status is "open"

# check status
reko.status # returns a strig "open"

# build in methods to check each status
reko.open?     # => true
reko.done?     # => false
reko.rejected? # => false

# build in methods to change the status
reko.open!     # => sets status to 0 ("open")
reko.done!     # => sets status to 1 ("done")
reko.rejected! # => sets status to 2 ("rejected")

Clone this wiki locally