Module: TokenUtil
- Defined in:
- lib/token_util.rb
Class Method Summary collapse
- .create_token(size) ⇒ Object
- .create_token_regexp(size) ⇒ Object
- .create_unique_token(klass, column, size) ⇒ Object
Class Method Details
.create_token(size) ⇒ Object
3 4 5 |
# File 'lib/token_util.rb', line 3 def self.create_token(size) return size.times.map { rand(16).to_s(16) }.join end |
.create_token_regexp(size) ⇒ Object
15 16 17 |
# File 'lib/token_util.rb', line 15 def self.create_token_regexp(size) return /\A[0-9a-f]{#{size}}\z/ end |
.create_unique_token(klass, column, size) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/token_util.rb', line 7 def self.create_unique_token(klass, column, size) begin token = self.create_token(size) end while klass.exists?(column => token) return token end |