micro_token 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +36 -0
- data/.travis.yml +1 -1
- data/Rakefile +5 -1
- data/lib/micro_token.rb +20 -14
- data/lib/micro_token/version.rb +1 -1
- data/micro_token.gemspec +5 -5
- data/spec/lib/micro_token_spec.rb +16 -9
- metadata +29 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e7bf4f4097edfe7d0402eb9d90594e485c19c95
|
4
|
+
data.tar.gz: d274fd6bfa0a66bb7e073060b1b9a6a33f001804
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be32584cf05905e4ae13ec370b642a247105f2c726ea70ca9c57b272dc95f7c55c37c18bc02f636b1a62d41cc52998a4747b22c185914f7336cebd64bce77b6c
|
7
|
+
data.tar.gz: 9a1f241a3f5eb17a20a2158797b9780486b57568552548725593e84fd7c5a344ebbcd01400116a21e1d8839bfd15e9e8e72e61ebc71e5cbbd95bca4baf0ef05d
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
Style/MethodDefParentheses:
|
2
|
+
EnforcedStyle: require_no_parentheses_except_multiline
|
3
|
+
|
4
|
+
Style/Documentation:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Style/AlignHash:
|
8
|
+
EnforcedHashRocketStyle: table
|
9
|
+
EnforcedColonStyle: table
|
10
|
+
|
11
|
+
Style/AlignParameters:
|
12
|
+
EnforcedStyle: with_fixed_indentation
|
13
|
+
|
14
|
+
Style/AndOr:
|
15
|
+
EnforcedStyle: conditionals
|
16
|
+
|
17
|
+
Style/SignalException:
|
18
|
+
EnforcedStyle: only_raise
|
19
|
+
|
20
|
+
Lint/AmbiguousOperator:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/ClassAndModuleChildren:
|
24
|
+
EnforcedStyle: compact
|
25
|
+
|
26
|
+
Style/EmptyLinesAroundClassBody:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/StringLiterals:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Metrics/LineLength:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/SingleLineMethods:
|
36
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
rvm:
|
2
|
-
- 2.
|
2
|
+
- 2.3.1
|
data/Rakefile
CHANGED
data/lib/micro_token.rb
CHANGED
@@ -2,45 +2,51 @@ require "micro_token/version"
|
|
2
2
|
require 'securerandom'
|
3
3
|
|
4
4
|
module MicroToken
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
SIMILAR_CHARS = %w(I l 1 0 O).freeze
|
6
|
+
LOWER_ALPHA_CHARS = ('a'..'z').to_a.freeze
|
7
|
+
UPPER_ALPHA_CHARS = ('A'..'Z').to_a.freeze
|
8
|
+
NUMERIC_CHARS = (0..9).map(&:to_s).freeze
|
9
|
+
ALPHA_CHARS = (LOWER_ALPHA_CHARS + UPPER_ALPHA_CHARS).freeze
|
10
|
+
ALPHANUMERIC_CHARS = (ALPHA_CHARS + NUMERIC_CHARS).freeze
|
11
|
+
VISUALLY_DISTINCT_CHARS = (ALPHANUMERIC_CHARS - SIMILAR_CHARS).freeze
|
10
12
|
|
11
13
|
class << self
|
12
14
|
|
13
|
-
def generate
|
14
|
-
(1..length).collect {
|
15
|
+
def generate length = 8, format = :alphanumeric
|
16
|
+
(1..length).collect { send("generate_#{format}_char") }.join
|
15
17
|
end
|
16
18
|
|
17
19
|
private
|
18
20
|
|
19
|
-
def
|
21
|
+
def generate_distinct_char
|
22
|
+
pick_from(VISUALLY_DISTINCT_CHARS)
|
23
|
+
end
|
24
|
+
|
25
|
+
def generate_uppercase_char
|
20
26
|
pick_from(UPPER_ALPHA_CHARS)
|
21
27
|
end
|
22
28
|
|
23
|
-
def
|
29
|
+
def generate_lowercase_char
|
24
30
|
pick_from(LOWER_ALPHA_CHARS)
|
25
31
|
end
|
26
32
|
|
27
|
-
def
|
33
|
+
def generate_alphanumeric_char
|
28
34
|
pick_from(ALPHANUMERIC_CHARS)
|
29
35
|
end
|
30
36
|
|
31
|
-
def
|
37
|
+
def generate_numeric_char
|
32
38
|
pick_from(NUMERIC_CHARS)
|
33
39
|
end
|
34
40
|
|
35
|
-
def
|
41
|
+
def generate_alpha_char
|
36
42
|
pick_from(ALPHA_CHARS)
|
37
43
|
end
|
38
44
|
|
39
|
-
def rand
|
45
|
+
def rand n
|
40
46
|
SecureRandom.random_number(n)
|
41
47
|
end
|
42
48
|
|
43
|
-
def pick_from
|
49
|
+
def pick_from ary
|
44
50
|
ary[rand(ary.size)]
|
45
51
|
end
|
46
52
|
|
data/lib/micro_token/version.rb
CHANGED
data/micro_token.gemspec
CHANGED
@@ -8,18 +8,18 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = MicroToken::VERSION
|
9
9
|
spec.authors = ["James Harton"]
|
10
10
|
spec.email = ["jamesotron@gmail.com"]
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage = "https://github.com/
|
11
|
+
spec.description = 'A tiny random token generator'
|
12
|
+
spec.summary = 'A tiny random token generator'
|
13
|
+
spec.homepage = "https://github.com/oshpark/micro_token"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files = `git ls-files`.split(
|
16
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
-
%w
|
22
|
+
%w(rake rspec rubocop).each do |dep|
|
23
23
|
spec.add_development_dependency dep
|
24
24
|
end
|
25
25
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'micro_token'
|
2
2
|
|
3
3
|
describe MicroToken do
|
4
|
-
|
5
4
|
describe '#generate' do
|
6
|
-
|
7
5
|
context 'with length' do
|
8
6
|
context 'set to 12' do
|
9
7
|
let(:length) { 12 }
|
@@ -22,14 +20,14 @@ describe MicroToken do
|
|
22
20
|
end
|
23
21
|
|
24
22
|
context 'with format' do
|
25
|
-
subject { MicroToken.generate(
|
23
|
+
subject { MicroToken.generate(80, format) }
|
26
24
|
|
27
25
|
context 'set to alphanumeric' do
|
28
26
|
let(:format) { :alphanumeric }
|
29
27
|
|
30
28
|
23.times do
|
31
29
|
it 'contains only alphanumeric characters' do
|
32
|
-
expect(subject.split.all? { |c| c =~ /[a-zA-Z0-9]/ }).to
|
30
|
+
expect(subject.split.all? { |c| c =~ /[a-zA-Z0-9]/ }).to be_truthy
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
@@ -39,7 +37,7 @@ describe MicroToken do
|
|
39
37
|
|
40
38
|
23.times do
|
41
39
|
it 'contains only numerals' do
|
42
|
-
expect(subject.split.all? { |c| c =~ /[0-9]/ }).to
|
40
|
+
expect(subject.split.all? { |c| c =~ /[0-9]/ }).to be_truthy
|
43
41
|
end
|
44
42
|
end
|
45
43
|
end
|
@@ -49,7 +47,7 @@ describe MicroToken do
|
|
49
47
|
|
50
48
|
23.times do
|
51
49
|
it 'contains only letters' do
|
52
|
-
expect(subject.split.all? { |c| c =~ /[a-zA-Z]/ }).to
|
50
|
+
expect(subject.split.all? { |c| c =~ /[a-zA-Z]/ }).to be_truthy
|
53
51
|
end
|
54
52
|
end
|
55
53
|
end
|
@@ -59,7 +57,7 @@ describe MicroToken do
|
|
59
57
|
|
60
58
|
23.times do
|
61
59
|
it 'contains only uppercase letters' do
|
62
|
-
expect(subject.split.all? { |c| c =~ /[A-Z]/ }).to
|
60
|
+
expect(subject.split.all? { |c| c =~ /[A-Z]/ }).to be_truthy
|
63
61
|
end
|
64
62
|
end
|
65
63
|
end
|
@@ -69,10 +67,19 @@ describe MicroToken do
|
|
69
67
|
|
70
68
|
23.times do
|
71
69
|
it 'contains only lowercase letters' do
|
72
|
-
expect(subject.split.all? { |c| c =~ /[a-z]/ }).to
|
70
|
+
expect(subject.split.all? { |c| c =~ /[a-z]/ }).to be_truthy
|
73
71
|
end
|
74
72
|
end
|
75
73
|
end
|
76
|
-
end
|
77
74
|
|
75
|
+
context 'set to distinct' do
|
76
|
+
let(:format) { :distinct }
|
77
|
+
|
78
|
+
23.times do
|
79
|
+
it "doesn't contain visually similar characters" do
|
80
|
+
expect(subject.split.all? { |c| c =~ /[Il10O]/ }).to be_falsy
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
78
85
|
end
|
metadata
CHANGED
@@ -1,55 +1,69 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Harton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
description: A tiny random token generator
|
@@ -59,8 +73,9 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
78
|
+
- ".travis.yml"
|
64
79
|
- Gemfile
|
65
80
|
- LICENSE.txt
|
66
81
|
- README.md
|
@@ -69,7 +84,7 @@ files:
|
|
69
84
|
- lib/micro_token/version.rb
|
70
85
|
- micro_token.gemspec
|
71
86
|
- spec/lib/micro_token_spec.rb
|
72
|
-
homepage: https://github.com/
|
87
|
+
homepage: https://github.com/oshpark/micro_token
|
73
88
|
licenses:
|
74
89
|
- MIT
|
75
90
|
metadata: {}
|
@@ -79,17 +94,17 @@ require_paths:
|
|
79
94
|
- lib
|
80
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
96
|
requirements:
|
82
|
-
- -
|
97
|
+
- - ">="
|
83
98
|
- !ruby/object:Gem::Version
|
84
99
|
version: '0'
|
85
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
101
|
requirements:
|
87
|
-
- -
|
102
|
+
- - ">="
|
88
103
|
- !ruby/object:Gem::Version
|
89
104
|
version: '0'
|
90
105
|
requirements: []
|
91
106
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.5.1
|
93
108
|
signing_key:
|
94
109
|
specification_version: 4
|
95
110
|
summary: A tiny random token generator
|