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.
14 15 16 17 |
# File 'lib/has_a_token/generator.rb', line 14 def initialize(charset: :urlsafe_base64, length: nil) @length = length || (charset == :unambiguous ? 5 : 24) @charset = charset end |
Instance Method Details
#generate ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/has_a_token/generator.rb', line 23 def generate case @charset when :unambiguous generate_unambiguous_token else generate_secure_token end end |