Skip to content

Instantly share code, notes, and snippets.

@janjiss
Created December 14, 2015 13:58
Show Gist options
  • Save janjiss/54f27b22aca58ca18b28 to your computer and use it in GitHub Desktop.
Save janjiss/54f27b22aca58ca18b28 to your computer and use it in GitHub Desktop.
class SendDayResults
ELIGIBLE_ROLES = {regular: 1, vip: 2}
attr_reader :user
def initialize(user)
@user = user
end
def call
GamesMailer.send_results_for_the_day(user) if user_eligible_for_notification?
end
def user_eligible_for_notification?
user_is_in_eligable_role? && users_notifications_are_enabled? && user_has_participated_in_any_games?
end
def user_is_in_eligable_role?
user.role == ELIGIBLE_ROLES[:regular] || user.role == ELIGIBLE_ROLES[:vip]
end
def users_notifications_are_enabled?
user.settings.where(notifications_enabled: true).any?
end
def user_has_participated_in_any_games?
user.games.where(participated: true).any?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment