Class: Accountability::Inventory::InventoryItem
- Inherits:
-
Object
- Object
- Accountability::Inventory::InventoryItem
- Defined in:
- app/models/accountability/inventory.rb
Instance Attribute Summary collapse
-
#inventory ⇒ Object
Returns the value of attribute inventory.
-
#product ⇒ Object
Returns the value of attribute product.
-
#record ⇒ Object
Returns the value of attribute record.
Instance Method Summary collapse
- #available? ⇒ Boolean
-
#initialize(record:, product:, inventory:) ⇒ InventoryItem
constructor
A new instance of InventoryItem.
- #price ⇒ Object
- #unavailable? ⇒ Boolean
Constructor Details
#initialize(record:, product:, inventory:) ⇒ InventoryItem
Returns a new instance of InventoryItem.
61 62 63 64 65 66 67 68 69 |
# File 'app/models/accountability/inventory.rb', line 61 def initialize(record:, product:, inventory:) @record = record @product = product @inventory = inventory # Expose source record through offerable's name record_alias = product.offerable_category.to_sym alias :"#{record_alias}" record end |
Instance Attribute Details
#inventory ⇒ Object
Returns the value of attribute inventory.
59 60 61 |
# File 'app/models/accountability/inventory.rb', line 59 def inventory @inventory end |
#product ⇒ Object
Returns the value of attribute product.
59 60 61 |
# File 'app/models/accountability/inventory.rb', line 59 def product @product end |
#record ⇒ Object
Returns the value of attribute record.
59 60 61 |
# File 'app/models/accountability/inventory.rb', line 59 def record @record end |
Instance Method Details
#available? ⇒ Boolean
77 78 79 80 81 |
# File 'app/models/accountability/inventory.rb', line 77 def available? return @available unless @available.nil? @available = inventory.available_source_ids.include? record.id end |
#price ⇒ Object
71 72 73 74 75 |
# File 'app/models/accountability/inventory.rb', line 71 def price # Iterating pre-loaded content is faster with Ruby than an N+1 in SQL price_override = record.price_overrides.find { |override| override.product_id == product.id } price_override&.price || product.price end |
#unavailable? ⇒ Boolean
83 84 85 |
# File 'app/models/accountability/inventory.rb', line 83 def unavailable? !available? end |