micro_token 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/micro_token.rb +35 -18
- data/lib/micro_token/version.rb +1 -1
- data/spec/lib/micro_token_spec.rb +20 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 344e232941e019cafdbe2fdb47cd6c0a587b64a1
|
4
|
+
data.tar.gz: b2bc64c84ecee92c11d48b1f38a896a2992a149a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c296227b6658ed366140097cbf72d766fe293a641cd8f42a4688194223aa8d729fa466e8fbb53602154601aa461ddf3cf7ea5faea18428b29314047cc181e103
|
7
|
+
data.tar.gz: 670fd4f827010631d2764509e4dc0645bb60514022375029147216071b6d2778c07938a3d40d5d40335253b0c342d067e329b03bb8d96d4cb29830131dd9cb4e
|
data/lib/micro_token.rb
CHANGED
@@ -2,30 +2,47 @@ require "micro_token/version"
|
|
2
2
|
require 'securerandom'
|
3
3
|
|
4
4
|
module MicroToken
|
5
|
-
|
5
|
+
LOWER_ALPHA_CHARS = ('a'..'z').to_a
|
6
|
+
UPPER_ALPHA_CHARS = ('A'..'Z').to_a
|
7
|
+
NUMERIC_CHARS = (0..9).to_a
|
8
|
+
ALPHA_CHARS = LOWER_ALPHA_CHARS + UPPER_ALPHA_CHARS
|
9
|
+
ALPHANUMERIC_CHARS = ALPHA_CHARS + NUMERIC_CHARS
|
6
10
|
|
7
|
-
|
8
|
-
(1..length).collect { self.send("_generate_#{format}_char") }.join
|
9
|
-
end
|
11
|
+
class << self
|
10
12
|
|
11
|
-
|
13
|
+
def generate(length=8,format=:alphanumeric)
|
14
|
+
(1..length).collect { self.send("_generate_#{format}_char") }.join
|
15
|
+
end
|
12
16
|
|
13
|
-
|
14
|
-
(i = rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr
|
15
|
-
end
|
17
|
+
private
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
def _generate_uppercase_char
|
20
|
+
pick_from(UPPER_ALPHA_CHARS)
|
21
|
+
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
def _generate_lowercase_char
|
24
|
+
pick_from(LOWER_ALPHA_CHARS)
|
25
|
+
end
|
26
|
+
|
27
|
+
def _generate_alphanumeric_char
|
28
|
+
pick_from(ALPHANUMERIC_CHARS)
|
29
|
+
end
|
24
30
|
|
25
|
-
|
31
|
+
def _generate_numeric_char
|
32
|
+
pick_from(NUMERIC_CHARS)
|
33
|
+
end
|
34
|
+
|
35
|
+
def _generate_alpha_char
|
36
|
+
pick_from(ALPHA_CHARS)
|
37
|
+
end
|
38
|
+
|
39
|
+
def rand(n)
|
40
|
+
SecureRandom.random_number(n)
|
41
|
+
end
|
42
|
+
|
43
|
+
def pick_from(ary)
|
44
|
+
ary[rand(ary.size)]
|
45
|
+
end
|
26
46
|
|
27
|
-
def rand(n)
|
28
|
-
SecureRandom.random_number(n)
|
29
47
|
end
|
30
48
|
end
|
31
|
-
|
data/lib/micro_token/version.rb
CHANGED
@@ -53,6 +53,26 @@ describe MicroToken do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
context 'set to uppercase' do
|
58
|
+
let(:format) { :uppercase }
|
59
|
+
|
60
|
+
23.times do
|
61
|
+
it 'contains only uppercase letters' do
|
62
|
+
expect(subject.split.all? { |c| c =~ /[A-Z]/ }).to be_true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'set to lowercase' do
|
68
|
+
let(:format) { :lowercase }
|
69
|
+
|
70
|
+
23.times do
|
71
|
+
it 'contains only lowercase letters' do
|
72
|
+
expect(subject.split.all? { |c| c =~ /[a-z]/ }).to be_true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
56
76
|
end
|
57
77
|
|
58
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: micro_token
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Harton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
92
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.0.
|
93
|
+
rubygems_version: 2.0.0
|
94
94
|
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: A tiny random token generator
|