Class: HasAToken::Generator
- Inherits:
-
Object
- Object
- HasAToken::Generator
- Includes:
- Contracts::Builtin, Contracts::Core
- Defined in:
- lib/has_a_token/generator.rb
Overview
Configurable generator for build unique tokens
Constant Summary collapse
- UNAMBIGUOUS_CHARSET =
%w( 2 3 4 6 7 9 A C D E F G H J K M N P Q R T V W X Y Z ).freeze
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(charset: :urlsafe_base64, length: nil) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(charset: :urlsafe_base64, length: nil) ⇒ Generator
Returns a new instance of Generator.
15 16 17 18 |
# File 'lib/has_a_token/generator.rb', line 15 def initialize(charset: :urlsafe_base64, length: nil) @length = length || (charset == :unambiguous ? 5 : 24) @charset = charset end |
Instance Method Details
#generate ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/has_a_token/generator.rb', line 24 def generate case @charset when :unambiguous generate_charset_token(UNAMBIGUOUS_CHARSET) when :alphabetical generate_charset_token(("A".."Z").to_a) else generate_secure_token end end |