Class: TokenBox::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/pasaporte/token_box.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lifetime) ⇒ Token

Returns a new instance of Token.



12
13
14
15
# File 'lib/pasaporte/token_box.rb', line 12

def initialize(lifetime)
  @will_expire = Time.now.utc + lifetime
  @token = (0...TOKEN_SIZE).inject("") { |ret,_| ret << CHARS[rand(CHARS.length)] }
end

Instance Attribute Details

#tokenObject (readonly) Also known as: to_s

Returns the value of attribute token.



9
10
11
# File 'lib/pasaporte/token_box.rb', line 9

def token
  @token
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/pasaporte/token_box.rb', line 17

def expired?
  @will_expire < Time.now.utc
end

#inspectObject



21
22
23
# File 'lib/pasaporte/token_box.rb', line 21

def inspect
  "#{@token}:#{'exp' if expired?}"
end