Class: Accountability::Inventory

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
app/models/accountability/inventory.rb

Defined Under Namespace

Classes: InventoryItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product, available_only: false) ⇒ Inventory

Returns a new instance of Inventory.



22
23
24
25
# File 'app/models/accountability/inventory.rb', line 22

def initialize(product, available_only: false)
  @product = product
  @scope_availability = available_only
end

Instance Attribute Details

#productObject

Returns the value of attribute product.



17
18
19
# File 'app/models/accountability/inventory.rb', line 17

def product
  @product
end

Instance Method Details

#availableObject



34
35
36
37
38
# File 'app/models/accountability/inventory.rb', line 34

def available
  @scope_availability = true

  self
end

#collectionObject



27
28
29
30
31
32
# File 'app/models/accountability/inventory.rb', line 27

def collection
  records = source_class.where(**source_scope)
  records = records.public_send(offerable_template.whitelist) if scope_availability?

  records.map { |record| InventoryItem.new(record: record, product: product) }
end