Module: Ticket::SaleTransitions::ClassMethods

Defined in:
app/models/ticket/sale_transitions.rb

Instance Method Summary collapse

Instance Method Details

#attempt_transition(tickets, state) ⇒ Object



39
40
41
42
43
44
45
46
# File 'app/models/ticket/sale_transitions.rb', line 39

def attempt_transition(tickets, state)
  begin
    tickets.map(&state)
    yield
  rescue Transitions::InvalidTransition
    logger.info "Trying to transition ticket [#{}] on_sale, transition failed"
  end
end

#put_on_sale(tickets) ⇒ Object



31
32
33
34
35
36
37
# File 'app/models/ticket/sale_transitions.rb', line 31

def put_on_sale(tickets)
  return false if tickets.blank?
  attempt_transition(tickets, :on_sale) do
    Ticket.update_all({ :state => :on_sale }, { :id => tickets.collect(&:id)})
  end
  tickets.first.show.refresh_stats
end

#take_off_sale(tickets) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'app/models/ticket/sale_transitions.rb', line 21

def take_off_sale(tickets)
  return false if tickets.blank?
  attempt_transition(tickets, :off_sale) do
    Ticket.update_all({ :state => :off_sale }, { :id => tickets.collect(&:id)})
  end
  Rails.logger.info ("Completed off saling!")
  tickets.first.show.refresh_stats
  Rails.logger.info ("Completed off sailing!")
end