Sha256: 6b2b3a7ecb9e390c39fd894466244a6d48238732aa8b170733a0ccedac0b067d

Contents?: true

Size: 606 Bytes

Versions: 18

Compression:

Stored size: 606 Bytes

Contents

module WithReminders

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

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

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

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

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

  def remind!
    send_reminder! if should_send_reminder?
  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mumuki-laboratory-5.3.0 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.2.1 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.2.0 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.1.1 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.1.0 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.0.12 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.0.11 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.0.10 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.0.9 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.0.8 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.0.7 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.0.6 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.0.5 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.0.4 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.0.3 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.0.2 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.0.1 app/models/concerns/with_reminders.rb
mumuki-laboratory-5.0.0 app/models/concerns/with_reminders.rb