diff options
author | David Gay <david@davidgay.org> | 2021-05-23 17:06:34 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-23 17:06:34 -0400 |
commit | aba212e13062c43a1192ef885b05145ac1cc9fe7 (patch) | |
tree | 61e3850ec0c86913a7e2d42076bcd73aa59f480a /app/models/concerns | |
parent | 44facc2e567eb3c045ce082428f42276e45b0202 (diff) |
Bazaar with buy orders, sell orders, and order cancellation
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/destroy_if_zero_quantity.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/models/concerns/destroy_if_zero_quantity.rb b/app/models/concerns/destroy_if_zero_quantity.rb new file mode 100644 index 0000000..6fdfb3e --- /dev/null +++ b/app/models/concerns/destroy_if_zero_quantity.rb @@ -0,0 +1,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 |