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
- #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
89 90 91 |
# File 'app/models/effective/event_notification.rb', line 89 def email_template 'event_' + category.to_s.parameterize.underscore end |
#notify!(force: false, event_registrants: nil) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'app/models/effective/event_notification.rb', line 142 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) opts = { from: from, subject: subject, body: body } event_registrants.each do |event_registrant| EffectiveEvents.send_email(email_template, event_registrant, opts) end update_column(:completed_at, Time.zone.now) end |
#notify_now? ⇒ Boolean
def notifiable?
started_at.blank? && completed_at.blank?
end
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/models/effective/event_notification.rb', line 121 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
93 94 95 |
# File 'app/models/effective/event_notification.rb', line 93 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' }
85 86 87 |
# File 'app/models/effective/event_notification.rb', line 85 def to_s 'event notification' end |