Sha256: e94bf61b7774ca0c171b4ee02b312d7ae664fa9e2780b76b92d4cac0b73794ca
Contents?: true
Size: 1012 Bytes
Versions: 23
Compression:
Stored size: 1012 Bytes
Contents
module Ticket::SaleTransitions extend ActiveSupport::Concern def take_off_sale begin off_sale! rescue Transitions::InvalidTransition return false end end def put_on_sale begin on_sale! rescue Transitions::InvalidTransition return false end end module ClassMethods 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 end 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 end 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 end end
Version data entries
23 entries across 23 versions & 1 rubygems