# frozen_string_literal: true class ReviewerReminder def initialize @collection = reminder_collection end def count @collection.count end alias size count def reminders @reminders ||= @collection.to_hash.map { |r| OpenStruct.new(r) } end def send_all reminders.each do |reminder| ReviewerMailer.reminder(reminder).deliver_now end end private def reminder_collection sql = "select u.name, u.email, c.test_hash, c.project from reviewer_votes rev inner join users u on u.id = rev.user_id inner join candidates c on c.id = rev.candidate_id where rev.vote = 0 and rev.veto = 0 and u.active is not false;" ActiveRecord::Base.connection.exec_query(sql) end end