Class: MiniToken

Inherits:
Struct
  • Object
show all
Defined in:
lib/mini_token.rb

Constant Summary collapse

TOKEN_SIZE =
6
TOKEN_CHARACTERS =
(('A'..'Z').to_a+('a'..'z').to_a+('0'..'9').to_a)
DB_PATH =
File.expand_path(File.join(File.dirname(__FILE__), '..', 'db'))

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#dbObject

Returns the value of attribute db

Returns:

  • (Object)

    the current value of db



4
5
6
# File 'lib/mini_token.rb', line 4

def db
  @db
end

#tokenObject

Returns the value of attribute token

Returns:

  • (Object)

    the current value of token



4
5
6
# File 'lib/mini_token.rb', line 4

def token
  @token
end

Class Method Details

.allObject



30
31
32
33
# File 'lib/mini_token.rb', line 30

def all
  connection
  @db.all
end

.delete_token(param) ⇒ Object



19
20
21
22
# File 'lib/mini_token.rb', line 19

def delete_token(param)
  connection
  @db.filter(:token => param).delete
end

.find(param) ⇒ Object



24
25
26
27
28
# File 'lib/mini_token.rb', line 24

def find(param)
  connection
  t = @db.first(:token => param)
  t[:token] unless t.nil?
end

.output(size = nil) ⇒ Object



10
11
12
# File 'lib/mini_token.rb', line 10

def output(size = nil)
  generate { @token_size = size.nil? ? TOKEN_SIZE : size }
end

.truncate_tokensObject



14
15
16
17
# File 'lib/mini_token.rb', line 14

def truncate_tokens
  connection
  @db.truncate
end