Created
September 11, 2012 05:44
-
-
Save bemurphy/3696235 to your computer and use it in GitHub Desktop.
InvitationSet
This file contains 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 InvitationSet | |
attr_reader :organization | |
def initialize(organization) | |
@organization = organization | |
end | |
def invite(email) | |
invite_code = Token.generate(6).upcase | |
key.zadd(Time.now.to_i, invite_code) | |
# deliver(email, invite_code) | |
invite_code | |
end | |
def invited?(invite_code) | |
purge_old | |
key.zscore(invite_code.upcase).to_i > 0 | |
end | |
def purge_old(days = 7, start_time = Time.now - (days * 86_400)) | |
key.zremrangebyscore 0, start_time.to_i | |
end | |
def key | |
organization.key[:invites] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could also TTL on #invite so an unused set is harvested after a time, but probably overkill at first.