Reservation Flags - YaleSTC/reservations GitHub Wiki

Flagging Reservations

flags is a bitmask that holds miscellaneous booleans.

Basic Usage

To use any of the currently existing flags, pass the flag's symbol to these methods: flagged?(flag), flag(flag), and unflag(flag). Note that you must call save after changing flags.

To assign multiple flags at once, you can use | to concatenate them, e.g.

res.flags |= Reservation::FLAGS[:request] | Reservation::FLAGS[:expired]
res.save!

Current Flags

  • request, used to remember which reservations started off as requests
  • broken, used to mark a reservation that resulted in broken equipment (NOT YET IMPLEMENTED, see issue #1216)
  • lost, used to mark a reservation where the equipment was lost (NOT YET IMPLEMENTED, see issue #1216)
  • fined, used to mark a reservation that has incurred a fine (NOT YET IMPLEMENTED, see issue #1216)
  • missed_email_sent, used to remember if we've sent a missed notification email so we don't spam users.
  • expired, used to mark requests that were denied because the start date passed before the request could be approved or denied

Adding a New Flag

To add a new flag, you will need to add it to the FLAGS hash in the reservation model.

  FLAGS = { request: (1 << 1), broken: (1 << 2), lost: (1 << 3),
            fined: (1 << 4), missed_email_sent: (1 << 5),
            expired: (1 << 6) }

The value that your new flag maps to should be a shift of one greater than whatever the last shift is. In this case, that would be (1 << 6).

  FLAGS = { request: (1 << 1), broken: (1 << 2), lost: (1 << 3),
            fined: (1 << 4), missed_email_sent: (1 << 5), 
            expired: (1 << 6), your_new_flag: (1 << 7) }

You can now use your new flag with the flagged?(flag), flag(flag), and unflag(flag) methods!