Class: Effective::EventTicket
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::EventTicket
- Defined in:
- app/models/effective/event_ticket.rb
Constant Summary collapse
- CATEGORIES =
['Regular', 'Member Only', 'Member or Non-Member']
Instance Method Summary collapse
- #capacity_available ⇒ Object
- #member_only? ⇒ Boolean
- #member_or_non_member? ⇒ Boolean
- #non_waitlisted_event_registrants_count ⇒ Object
- #purchased_event_registrants_count ⇒ Object
- #questions ⇒ Object
- #registered_event_registrants_count ⇒ Object
- #regular? ⇒ Boolean
- #to_s ⇒ Object
-
#update_waitlist! ⇒ Object
This is supposed to be an indempotent big update the world thing.
- #waitlisted_event_registrants_count ⇒ Object
Instance Method Details
#capacity_available ⇒ Object
98 99 100 101 |
# File 'app/models/effective/event_ticket.rb', line 98 def capacity_available return nil if capacity.blank? [(capacity - registered_event_registrants_count), 0].max end |
#member_only? ⇒ Boolean
127 128 129 |
# File 'app/models/effective/event_ticket.rb', line 127 def member_only? category == 'Member Only' end |
#member_or_non_member? ⇒ Boolean
131 132 133 |
# File 'app/models/effective/event_ticket.rb', line 131 def member_or_non_member? category == 'Member or Non-Member' end |
#non_waitlisted_event_registrants_count ⇒ Object
111 112 113 |
# File 'app/models/effective/event_ticket.rb', line 111 def non_waitlisted_event_registrants_count registered_event_registrants.where(waitlisted: false).or(registered_event_registrants.where(waitlisted: true, promoted: true)) end |
#purchased_event_registrants_count ⇒ Object
107 108 109 |
# File 'app/models/effective/event_ticket.rb', line 107 def purchased_event_registrants_count purchased_event_registrants.length end |
#questions ⇒ Object
119 120 121 |
# File 'app/models/effective/event_ticket.rb', line 119 def questions [question1.presence, question2.presence, question3.presence].compact end |
#registered_event_registrants_count ⇒ Object
103 104 105 |
# File 'app/models/effective/event_ticket.rb', line 103 def registered_event_registrants_count registered_event_registrants.length end |
#regular? ⇒ Boolean
123 124 125 |
# File 'app/models/effective/event_ticket.rb', line 123 def regular? category == 'Regular' end |
#to_s ⇒ Object
73 74 75 |
# File 'app/models/effective/event_ticket.rb', line 73 def to_s title.presence || 'New Event Ticket' end |
#update_waitlist! ⇒ Object
This is supposed to be an indempotent big update the world thing
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/models/effective/event_ticket.rb', line 78 def update_waitlist! return false unless waitlist? changed_event_registrants = registered_event_registrants.each_with_index.map do |event_registrant, index| next if event_registrant.purchased? waitlisted_was = event_registrant.waitlisted? waitlisted = (waitlist? && index >= capacity) next if waitlisted == waitlisted_was event_registrant.update!(waitlisted: waitlisted) # Updates price event_registrant end.compact orders = changed_event_registrants.flat_map { |event_registrant| event_registrant.deferred_orders }.compact.uniq orders.each { |order| order.update_purchasable_attributes! } true end |
#waitlisted_event_registrants_count ⇒ Object
115 116 117 |
# File 'app/models/effective/event_ticket.rb', line 115 def waitlisted_event_registrants_count registered_event_registrants.where(waitlisted: true, promoted: false).length end |