Class: Wee::IdGenerator::Secure

Inherits:
Wee::IdGenerator show all
Defined in:
lib/wee/id_generator.rb

Overview

Returned ids are unique with a very high probability and it’s very hard to guess the next or any used id.

Instance Method Summary collapse

Constructor Details

#initialize(salt = 'wee') ⇒ Secure

Returns a new instance of Secure.



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/wee/id_generator.rb', line 39

def initialize(salt='wee')
  @salt = salt

  @use_secure = false
  if defined?(::SecureRandom)
    begin
      @use_secure = true if next_secure != next_secure
    rescue NotImplementedError
    end
  end
end

Instance Method Details

#nextObject



51
52
53
# File 'lib/wee/id_generator.rb', line 51

def next
  pack(@use_secure ? next_secure : next_md5)
end