Class: Workarea::Fulfillment::Item

Inherits:
Object
  • Object
show all
Includes:
ApplicationDocument
Defined in:
app/models/workarea/fulfillment/item.rb

Instance Method Summary collapse

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list

Methods included from Mongoid::Document

#embedded_children

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



17
18
19
20
21
22
23
24
# File 'app/models/workarea/fulfillment/item.rb', line 17

def method_missing(method_name, *args)
  if method_name =~ /^quantity_/
    status = method_name.to_s.gsub(/^quantity_/, '')
    events.where(status: status).sum(&:quantity)
  else
    super
  end
end

Instance Method Details

#quantity_pendingObject



13
14
15
# File 'app/models/workarea/fulfillment/item.rb', line 13

def quantity_pending
  [0, quantity - events.sum(&:quantity)].max
end