Created
December 14, 2015 13:58
-
-
Save janjiss/54f27b22aca58ca18b28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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