Class: Comable::Stock
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Comable::Stock
- Includes:
- Ransackable, SkuChoice, SkuItem
- Defined in:
- app/models/comable/stock.rb
Overview
在庫モデル。商品に複数紐付き、品数やSKU(Stock Keeping Unit)情報を保持する。
Scope collapse
-
.stocked ⇒ Object
(also: unsold)
品切れでない在庫インスタンスを返す.
-
.unstocked ⇒ Object
(also: soldout)
品切れの在庫インスタンスを返す.
Instance Method Summary collapse
-
#stocked?(quantity: 1) ⇒ Boolean
(also: #unsold?)
在庫の有無を取得する.
-
#unstocked?(quantity: 1) ⇒ Boolean
(also: #soldout?)
在庫の有無を取得する.
Methods included from SkuChoice
Methods included from SkuItem
Class Method Details
.stocked ⇒ Object Also known as: unsold
品切れでない在庫インスタンスを返す
19 |
# File 'app/models/comable/stock.rb', line 19 scope :stocked, -> { where('quantity > ?', 0) } |
.unstocked ⇒ Object Also known as: soldout
品切れの在庫インスタンスを返す
28 |
# File 'app/models/comable/stock.rb', line 28 scope :unstocked, -> { where('quantity <= ?', 0) } |
Instance Method Details
#stocked?(quantity: 1) ⇒ Boolean Also known as: unsold?
在庫の有無を取得する
62 63 64 |
# File 'app/models/comable/stock.rb', line 62 def stocked?(quantity: 1) (self.quantity - quantity) >= 0 end |
#unstocked?(quantity: 1) ⇒ Boolean Also known as: soldout?
在庫の有無を取得する
78 79 80 |
# File 'app/models/comable/stock.rb', line 78 def unstocked?(quantity: 1) !stocked?(quantity: quantity) end |