Class: Effective::EventTicket

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/event_ticket.rb

Constant Summary collapse

CATEGORIES =
['Regular', 'Member Only', 'Member or Non-Member']

Instance Method Summary collapse

Instance Method Details

#capacity_availableObject



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

Returns:

  • (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

Returns:

  • (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_countObject



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_countObject



107
108
109
# File 'app/models/effective/event_ticket.rb', line 107

def purchased_event_registrants_count
  purchased_event_registrants.length
end

#questionsObject



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_countObject



103
104
105
# File 'app/models/effective/event_ticket.rb', line 103

def registered_event_registrants_count
  registered_event_registrants.length
end

#regular?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'app/models/effective/event_ticket.rb', line 123

def regular?
  category == 'Regular'
end

#to_sObject



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_countObject



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