Class: Effective::EventNotification
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::EventNotification
- Defined in:
- app/models/effective/event_notification.rb
Constant Summary collapse
- CATEGORIES =
['Registrant purchased']
- EMAIL_TEMPLATE_VARIABLES =
['event.name', 'event.date', 'event.url', 'ticket.name', 'registrant.name', 'registrant.email']
Instance Method Summary collapse
- #email_template ⇒ Object
- #email_template_variables ⇒ Object
- #notify!(force: false, event_registrants: nil) ⇒ Object
-
#notify_now? ⇒ Boolean
def notifiable? started_at.blank? && completed_at.blank? end.
- #registrant_purchased? ⇒ Boolean
-
#to_s ⇒ Object
validates :reminder, if: -> { reminder? || upcoming_reminder? || before_event_ends? }, presence: true, uniqueness: { scope: [:event_id, :category], message: ‘already exists’ }.
Instance Method Details
#email_template ⇒ Object
87 88 89 |
# File 'app/models/effective/event_notification.rb', line 87 def email_template 'event_' + category.to_s.parameterize.underscore end |
#email_template_variables ⇒ Object
91 92 93 |
# File 'app/models/effective/event_notification.rb', line 91 def email_template_variables EMAIL_TEMPLATE_VARIABLES end |
#notify!(force: false, event_registrants: nil) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'app/models/effective/event_notification.rb', line 144 def notify!(force: false, event_registrants: nil) return false unless (notify_now? || force) # We send one email to each registrant event_registrants ||= event.event_registrants.purchased update_column(:started_at, Time.zone.now) event_registrants.each do |event_registrant| next if event_registrant.email.blank? begin EffectiveEvents.send_email(email_template, event_registrant, email_notification_params) rescue => e EffectiveLogger.error(e., associated: event_registrant) if defined?(EffectiveLogger) ExceptionNotifier.notify_exception(e, data: { event_registrant_id: event_registrant.id, event_notification_id: id }) if defined?(ExceptionNotifier) raise(e) if Rails.env.test? || Rails.env.development? end end update_column(:completed_at, Time.zone.now) end |
#notify_now? ⇒ Boolean
def notifiable?
started_at.blank? && completed_at.blank?
end
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/models/effective/event_notification.rb', line 123 def notify_now? true #return false unless notifiable? # case category # when 'When event starts' # event.available? # when 'When event ends' # event.ended? # when 'Upcoming reminder' # !event.started? && event.start_at < (Time.zone.now + reminder) # when 'Reminder' # !event.ended? && event.start_at < (Time.zone.now - reminder) # when 'Before event ends' # !event.ended? && event.end_at.present? && event.end_at < (Time.zone.now + reminder) # else # raise('unexpected category') # end end |
#registrant_purchased? ⇒ Boolean
95 96 97 |
# File 'app/models/effective/event_notification.rb', line 95 def registrant_purchased? category == 'Registrant purchased' end |
#to_s ⇒ Object
validates :reminder, if: -> { reminder? || upcoming_reminder? || before_event_ends? },
presence: true, uniqueness: { scope: [:event_id, :category], message: 'already exists' }
83 84 85 |
# File 'app/models/effective/event_notification.rb', line 83 def to_s 'event notification' end |