Class: BookingState

Inherits:
Object
  • Object
show all
Defined in:
app/models/booking_state.rb

Overview

The state of a Booking.

When a Booking is created, it's in the pending state.

When the counterpart confirms, it goes to the accepted state.

When the counterpart rejects, it goes to the rejected state.

When either of the parts cancel, it goes to the cancelled state.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (String) label

Returns the label that describes the BookingState.

Returns:



12
13
14
# File 'app/models/booking_state.rb', line 12

def label
  @label
end

Instance Method Details

- (Boolean) accept(booking)

If the Booking is in the pending state, transition it to the accepted state.

If the Booking is in the accepted state, do nothing.

If the Booking is in the rejected or cancelled states, fail.

Parameters:

Returns:

  • (Boolean)

    whether any transition ocurred.



23
24
# File 'app/models/booking_state.rb', line 23

def accept booking
end

- (Boolean) cancel(booking)

If the Booking is in the pending, accepted or rejected states, transition it to the cancelled state.

If the Booking is in the cancelled state, do nothing.

Parameters:

Returns:

  • (Boolean)

    whether any transition ocurred.



45
46
# File 'app/models/booking_state.rb', line 45

def cancel booking
end

- (Boolean) reject(booking)

If the Booking is in the pending state, transition it to the rejected state.

If the Booking is in the rejected state, do nothing.

If the Booking is in the accepted or cancelled states, fail.

Parameters:

Returns:

  • (Boolean)

    whether any transition ocurred.



35
36
# File 'app/models/booking_state.rb', line 35

def reject booking
end