summaryrefslogtreecommitdiff
path: root/app/models/concerns/destroy_if_zero_quantity.rb
blob: 6fdfb3ec921b8be3935df3d882960f5231c405a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module DestroyIfZeroQuantity
  extend ActiveSupport::Concern

  included do
    after_save :destroy_if_zero_quantity
  end

  private
    def destroy_if_zero_quantity
      byebug
      if self.quantity == 0
        destroy
      elsif self.quantity < 0
        # TODO: Can improve this (at the least, with reporting, later).
        raise ItemQuantityError
      end
    end
end