Module: ActsAsHoldable::Holder::InstanceMethods
- Defined in:
- lib/acts_as_holdable/holder.rb
Instance Method Summary collapse
- #confirm_holding!(holding) ⇒ Object
- #hold!(holdable, opts = {}) ⇒ Object
- #hold_for(holdable, opts = {}) ⇒ Object
- #holder? ⇒ Boolean
- #unhold!(holding) ⇒ Object
Instance Method Details
#confirm_holding!(holding) ⇒ Object
57 58 59 60 61 62 |
# 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 = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# 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 = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# 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? ⇒ Boolean
64 65 66 |
# File 'lib/acts_as_holdable/holder.rb', line 64 def holder? self.class.holder? end |
#unhold!(holding) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/acts_as_holdable/holder.rb', line 37 def unhold!(holding) # deletes current holding ActsAsHoldable::Holding.destroy(holding.id) reload true end |