~cytrogen/gstack

ref: 8151fcd5895f8438445a3df47432d59e1cd099df gstack/test/fixtures/review-eval-enum.rb -rw-r--r-- 759 bytes
8151fcd5 — Garry Tan feat: /design-html skill — Pretext-native HTML from approved mockups (v0.14.0.0) (#653) 11 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Existing file on main: order model with status handling
class Order < ApplicationRecord
  STATUSES = %w[pending processing shipped delivered].freeze

  validates :status, inclusion: { in: STATUSES }

  def display_status
    case status
    when 'pending'    then 'Awaiting processing'
    when 'processing' then 'Being prepared'
    when 'shipped'    then 'On the way'
    when 'delivered'  then 'Delivered'
    end
  end

  def can_cancel?
    %w[pending processing].include?(status)
  end

  def notify_customer
    case status
    when 'pending'    then OrderMailer.confirmation(self).deliver_later
    when 'shipped'    then OrderMailer.shipped(self).deliver_later
    when 'delivered'  then OrderMailer.delivered(self).deliver_later
    end
  end
end