Sha256: e463597524b4291c1944fb14a376f101d833ab16088ab94f0818b6ae96cce74f

Contents?: true

Size: 1.64 KB

Versions: 7

Compression:

Stored size: 1.64 KB

Contents

module Ticket::Locker
  extend ActiveSupport::Concern

  module ClassMethods
    def lock(tickets, ticket_type, cart)
      tickets = Array.wrap(tickets)

      #
      # TODO: blow up if this ticket_type does not apply to this show
      #
      Rails.logger.debug(tickets.inspect)
      Ticket.where(:id => tickets).update_all({ :cart_id        => cart.id, 
                                                :ticket_type_id => ticket_type.id, 
                                                :cart_price     => ticket_type.price
                                                })
      tickets = Ticket.includes(:ticket_type).where(:id => tickets)
      Rails.logger.debug(tickets.inspect)
      cart << tickets
      ExpireTicketJob.enqueue(tickets.collect(&:id), cart.id)
      tickets
    end

    #
    # We pass cart so that we can ensure we're expiring the right transaction. The ticket could have moved
    # carts since the job was queued.
    #
    # If we come along and expire it, the patron will be bitter.
    #
    def unlock(tickets, cart)
      
      Ticket.where(:id => tickets)
            .where(:cart_id => cart)
            .uncommitted
            .update_all({ :cart_id        => nil, 
                          :ticket_type_id => nil,
                          :pass_id        => nil,  
                          :cart_price     => nil,
                          :sold_price     => nil,
                          :service_fee    => 0,
                          :discount_id    => nil
                        })
    end
  end

  #
  # This means ticket is in a cart and not sold.
  #
  def locked?
    !self.cart_id.nil? && !sold? && !comped?
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
artfully_ose-1.2.0 app/models/ticket/locker.rb
artfully_ose-1.2.0.beta.1 app/models/ticket/locker.rb
artfully_ose-1.2.0.alpha.2 app/models/ticket/locker.rb
artfully_ose-1.2.0.alpha.1 app/models/ticket/locker.rb
artfully_ose-1.2.0.pre.27 app/models/ticket/locker.rb
artfully_ose-1.2.0.pre.26 app/models/ticket/locker.rb
artfully_ose-1.2.0.pre.24 app/models/ticket/locker.rb