Socket
Book a DemoInstallSign in
Socket

token_generator

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

token_generator

0.0.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

TokenGenerator

Tiny class that generates friendly tokens using SecureRandom.

Installation

Add this line to your application's Gemfile:

gem 'token_generator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install token_generator

Usage

TokenGenerator acts as a namespace for the token method (see below about customising the generator).

The token method takes an integer (default 20) which is the number of characters.

Its second argument is the group size (default 5). If you don't want groups, pass 0.

require 'token_generator'

TokenGenerator.token
# => "PXQE2-ZQWTN-PVFQ9-KYWNC"

TokenGenerator.token(12)
# => "KFAE2-YWJQC-PX"

TokenGenerator.token(12,3)
# => "EYV-XAZ-VFF-47N"

TokenGenerator.token(50,0)
# => "XN76KFH9AC2AA66AXJAPT6RNMVCYJ22E4AD4ZK7E9PNFH6XDGC"

Customising the generator

include TokenGenerator in your own class, and override charset, length, group_size

Or, to customise the global TokenGenerator by setting accessors.

class DNAGen
  include TokenGenerator

  def charset
    ['C', 'G', 'T', 'A']
  end

  def group_size
    3
  end

  def length
    21
  end
end

gen = DNAGen.new

gen.token
# => "TTT-CGT-TTT-AAA-GTG-AGA-TCC"

gen.token(120)
# => "CTC-ACT-TGC-GTG-ATG-AGA-AAA-GCT-AGG-GAC-AAT-CCC-AAC-GTT-AGA-TAA-TCA-TCG-CCT-TCT-ACG-CAT-ATG-AAG-ACA-TGA-CCT-TGC-AAT-TCA-CCA-GGT-CTC-CAG-TAC-GAT-AGT-ATC-TCC-TCC"

Contributing

  • Fork it ( https://github.com/i2w/token_generator/fork )
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request

FAQs

Package last updated on 28 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.