Class: SpreeCmCommissioner::CachedInventoryItem
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::CachedInventoryItem
- Defined in:
- lib/spree_cm_commissioner/cached_inventory_item.rb
Overview
Both stock pools of one inventory item, as Redis currently holds them.
quantity_available / quantity_on_hold are ALWAYS the public pool and quantity_locked / quantity_locked_on_hold ALWAYS the withheld one, so a caller can answer for either without rebuilding — which is what lets Variant#in_stock? total them in a single pass.
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#inventory_hold_key ⇒ Object
readonly
Returns the value of attribute inventory_hold_key.
-
#inventory_item_id ⇒ Object
readonly
Returns the value of attribute inventory_item_id.
-
#inventory_key ⇒ Object
readonly
Returns the value of attribute inventory_key.
-
#max_capacity ⇒ Object
readonly
Returns the value of attribute max_capacity.
-
#quantity_available ⇒ Object
readonly
Returns the value of attribute quantity_available.
-
#quantity_locked ⇒ Object
readonly
Returns the value of attribute quantity_locked.
-
#quantity_locked_on_hold ⇒ Object
readonly
Returns the value of attribute quantity_locked_on_hold.
-
#quantity_on_hold ⇒ Object
readonly
Returns the value of attribute quantity_on_hold.
-
#variant_id ⇒ Object
readonly
Returns the value of attribute variant_id.
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#initialize(options = {}) ⇒ CachedInventoryItem
constructor
A new instance of CachedInventoryItem.
- #to_h ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CachedInventoryItem
Returns a new instance of CachedInventoryItem.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/spree_cm_commissioner/cached_inventory_item.rb', line 19 def initialize( = {}) @inventory_key = [:inventory_key] @inventory_hold_key = [:inventory_hold_key] @active = [:active] @quantity_available = [:quantity_available] @quantity_on_hold = [:quantity_on_hold] @quantity_locked = [:quantity_locked] @quantity_locked_on_hold = [:quantity_locked_on_hold] @max_capacity = [:max_capacity] @inventory_item_id = [:inventory_item_id] @variant_id = [:variant_id] end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
8 9 10 |
# File 'lib/spree_cm_commissioner/cached_inventory_item.rb', line 8 def active @active end |
#inventory_hold_key ⇒ Object (readonly)
Returns the value of attribute inventory_hold_key.
8 9 10 |
# File 'lib/spree_cm_commissioner/cached_inventory_item.rb', line 8 def inventory_hold_key @inventory_hold_key end |
#inventory_item_id ⇒ Object (readonly)
Returns the value of attribute inventory_item_id.
8 9 10 |
# File 'lib/spree_cm_commissioner/cached_inventory_item.rb', line 8 def inventory_item_id @inventory_item_id end |
#inventory_key ⇒ Object (readonly)
Returns the value of attribute inventory_key.
8 9 10 |
# File 'lib/spree_cm_commissioner/cached_inventory_item.rb', line 8 def inventory_key @inventory_key end |
#max_capacity ⇒ Object (readonly)
Returns the value of attribute max_capacity.
8 9 10 |
# File 'lib/spree_cm_commissioner/cached_inventory_item.rb', line 8 def max_capacity @max_capacity end |
#quantity_available ⇒ Object (readonly)
Returns the value of attribute quantity_available.
8 9 10 |
# File 'lib/spree_cm_commissioner/cached_inventory_item.rb', line 8 def quantity_available @quantity_available end |
#quantity_locked ⇒ Object (readonly)
Returns the value of attribute quantity_locked.
8 9 10 |
# File 'lib/spree_cm_commissioner/cached_inventory_item.rb', line 8 def quantity_locked @quantity_locked end |
#quantity_locked_on_hold ⇒ Object (readonly)
Returns the value of attribute quantity_locked_on_hold.
8 9 10 |
# File 'lib/spree_cm_commissioner/cached_inventory_item.rb', line 8 def quantity_locked_on_hold @quantity_locked_on_hold end |
#quantity_on_hold ⇒ Object (readonly)
Returns the value of attribute quantity_on_hold.
8 9 10 |
# File 'lib/spree_cm_commissioner/cached_inventory_item.rb', line 8 def quantity_on_hold @quantity_on_hold end |
#variant_id ⇒ Object (readonly)
Returns the value of attribute variant_id.
8 9 10 |
# File 'lib/spree_cm_commissioner/cached_inventory_item.rb', line 8 def variant_id @variant_id end |
Instance Method Details
#active? ⇒ Boolean
32 33 34 |
# File 'lib/spree_cm_commissioner/cached_inventory_item.rb', line 32 def active? active end |
#to_h ⇒ Object
36 37 38 39 40 |
# File 'lib/spree_cm_commissioner/cached_inventory_item.rb', line 36 def to_h instance_variables.each_with_object({}) do |var, hash| hash[var.to_s.delete('@').to_sym] = instance_variable_get(var) end end |