Module: WithReminders

Included in:
User
Defined in:
app/models/concerns/with_reminders.rb

Instance Method Summary collapse

Instance Method Details

#build_reminderObject



3
4
5
# File 'app/models/concerns/with_reminders.rb', line 3

def build_reminder
  UserMailer.new.we_miss_you_reminder(self, cycles_since(last_submission_date))
end

#cycles_since(time) ⇒ Object



12
13
14
# File 'app/models/concerns/with_reminders.rb', line 12

def cycles_since(time)
  ((Date.current - time.to_date) / Rails.configuration.reminder_frequency).to_i
end

#remider_due?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/models/concerns/with_reminders.rb', line 16

def remider_due?
  last_reminded_date.nil? || cycles_since(last_reminded_date) >= 1
end

#remind!Object



24
25
26
# File 'app/models/concerns/with_reminders.rb', line 24

def remind!
  send_reminder! if should_send_reminder?
end

#send_reminder!Object



7
8
9
10
# File 'app/models/concerns/with_reminders.rb', line 7

def send_reminder!
  build_reminder.deliver
  update! last_reminded: Time.now
end

#should_send_reminder?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/models/concerns/with_reminders.rb', line 20

def should_send_reminder?
  remider_due? && cycles_since(last_submission_date).between?(1, 3)
end