Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
InvitationSet
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
@bemurphy

This comment has been minimized.

Copy link
Owner Author

commented Sep 11, 2012

Could also TTL on #invite so an unused set is harvested after a time, but probably overkill at first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.