module ActsAsHoldable::Holder::InstanceMethods

Public Instance Methods

confirm_holding!(holding) click to toggle source
# File lib/acts_as_holdable/holder.rb, line 57
def confirm_holding!(holding)
  return false unless holding.job_pid
  Sidekiq::Status.unschedule(holding.job_pid)
  holding.update(job_pid: nil)
  holding
end
hold!(holdable, opts = {}) click to toggle source
# File lib/acts_as_holdable/holder.rb, line 26
def hold!(holdable, opts = {})
  # validates availability
  holdable.check_availability!(opts) if holdable.class.holdable?

  holding_params = opts.merge(holder: self, holdable: holdable)
  holding = ActsAsHoldable::Holding.create!(holding_params)

  holdable.reload
  holding
end
hold_for(holdable, opts = {}) click to toggle source
# File lib/acts_as_holdable/holder.rb, line 44
def hold_for(holdable, opts = {})
  # Clean params for Bookings
  holding_opts = opts.except(:duration)

  # Creates the Booking
  holding = hold!(holdable, holding_opts)

  # Sets a Job to delete the Booking
  job = UnholdJob.set(wait: opts[:duration]).perform_later(holding.id)
  holding.update(job_pid: job.provider_job_id)
  holding
end
holder?() click to toggle source
# File lib/acts_as_holdable/holder.rb, line 64
def holder?
  self.class.holder?
end
unhold!(holding) click to toggle source
# File lib/acts_as_holdable/holder.rb, line 37
def unhold!(holding)
  # deletes current holding
  ActsAsHoldable::Holding.destroy(holding.id)
  reload
  true
end