Skip to content

Instantly share code, notes, and snippets.

@bemurphy
Created September 11, 2012 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bemurphy/3696235 to your computer and use it in GitHub Desktop.
Save bemurphy/3696235 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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