Skip to content

Instantly share code, notes, and snippets.

@roy
Created April 30, 2013 15:00
Show Gist options
  • Save roy/5489282 to your computer and use it in GitHub Desktop.
Save roy/5489282 to your computer and use it in GitHub Desktop.
# generate a validator proc
def generate_access_token
validator = ->(x){ !self.class.exists?(token: token) }
self.token = TokenGenerator.generate!(&validator)
end
require 'securerandom'
class TokenGenerator
def self.generate!(&validator)
begin
token = SecureRandom.hex(8)
end until validator.call(token)
token
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment