Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Reporter
def send_report
message = Report.new.create
Mailer.new("jjbohn@gmail.com", "jill@example.com", "Your report").send(message)
end
end
class User
def self.expired_logins
where("last_logged_in_at >= ?", 1.week.ago)
end
end
class Report
def user_report(user)
message = "Id: #{user.id}\n"
message += "Username: #{user.username}\n"
message += "Last Login: #{user.last_logged_in_at.strftime("%D")}\n"
message += "\n"
end
def create(user_repository=User)
user_repository.expired_logins.map do |user|
user_report(user)
end
end
end
class Mailer
attr_reader :from, :to, :subject
def initialize(from, to, subject)
@from, @to, @subject = from, to, subject
end
def send(message, mail=Mail)
mail.deliver do
from from
to to
subject subject
body message
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment