mongoid_token icon indicating copy to clipboard operation
mongoid_token copied to clipboard

Add lowercase and uppercase alphanumeric generators

Open vinc opened this issue 11 years ago • 1 comments

I wanted to generate lowercase alphanumeric tokens so I modified the Generator module to do that and the same for uppercase. I added %a and %A quite arbitrary, maybe there's a better letter.

I'm using the mongoid-4 branch and the code contains a new helper function rand_string_from_chars so my PR is based on this branch instead of master.

vinc avatar Jun 15 '14 10:06 vinc

@vinc Thanks for this - I hadn't considered that this might be a use case. The current master branch also resolves the build error you're having on Travis, with your branch.

The one thing I will note with your commits is that you transitioned some of the generator methods to rand_string_from_chars. Whilst this seems sensible, the less attractive methods for generating the tokens (which came out of an older pull request by another user) are significantly faster. This is the result of a quick benchmark comparing the 'ugly' version, with the rand_string_from_chars version (50,000 tokens of length 100):

ugly (50000)                    0.230000   0.000000   0.230000 (  0.227429)
rand_string_from_chars (50000)  1.360000   0.000000   1.360000 (  1.359790)

I've actually been meaning to migrate some of the other generator methods to the more optimal style.

If you don't mind rolling back some of those bigger changes, I'd be more than happy to include your upper and lower alphanumeric token!

Thanks again for your contribution! :cake:

thetron avatar Jul 12 '14 04:07 thetron