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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09c41a2a78efc178460945e450516498f9b0cd60
4
- data.tar.gz: ad169551a394ba2b1ba30788fe99a7d97416fece
3
+ metadata.gz: 2e7bf4f4097edfe7d0402eb9d90594e485c19c95
4
+ data.tar.gz: d274fd6bfa0a66bb7e073060b1b9a6a33f001804
5
5
  SHA512:
6
- metadata.gz: f34e869b6dc26d951167544d1b8209f6971f2fb7a29763fca2b4c2c2e46d58b844785a3343d9740b0530bc213c5250148667ec7dc74ad09e642084fd297a5ecc
7
- data.tar.gz: 8a73ae42572bf09023cee5215dd2ce529d93a4cc821f1a114898e190373d4f40e4e0bd4fe8bb1694a9f80ae0f36185bb6ccb321e4835ddc4d011d6b358815a7c
6
+ metadata.gz: be32584cf05905e4ae13ec370b642a247105f2c726ea70ca9c57b272dc95f7c55c37c18bc02f636b1a62d41cc52998a4747b22c185914f7336cebd64bce77b6c
7
+ data.tar.gz: 9a1f241a3f5eb17a20a2158797b9780486b57568552548725593e84fd7c5a344ebbcd01400116a21e1d8839bfd15e9e8e72e61ebc71e5cbbd95bca4baf0ef05d
@@ -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
@@ -1,2 +1,2 @@
1
1
  rvm:
2
- - 2.0.0
2
+ - 2.3.1
data/Rakefile CHANGED
@@ -1,4 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
3
5
  RSpec::Core::RakeTask.new(:spec)
4
- task default: :spec
6
+ RuboCop::RakeTask.new(:rubocop)
7
+
8
+ task default: [:rubocop, :spec]
@@ -2,45 +2,51 @@ require "micro_token/version"
2
2
  require 'securerandom'
3
3
 
4
4
  module MicroToken
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
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(length=8,format=:alphanumeric)
14
- (1..length).collect { self.send("_generate_#{format}_char") }.join
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 _generate_uppercase_char
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 _generate_lowercase_char
29
+ def generate_lowercase_char
24
30
  pick_from(LOWER_ALPHA_CHARS)
25
31
  end
26
32
 
27
- def _generate_alphanumeric_char
33
+ def generate_alphanumeric_char
28
34
  pick_from(ALPHANUMERIC_CHARS)
29
35
  end
30
36
 
31
- def _generate_numeric_char
37
+ def generate_numeric_char
32
38
  pick_from(NUMERIC_CHARS)
33
39
  end
34
40
 
35
- def _generate_alpha_char
41
+ def generate_alpha_char
36
42
  pick_from(ALPHA_CHARS)
37
43
  end
38
44
 
39
- def rand(n)
45
+ def rand n
40
46
  SecureRandom.random_number(n)
41
47
  end
42
48
 
43
- def pick_from(ary)
49
+ def pick_from ary
44
50
  ary[rand(ary.size)]
45
51
  end
46
52
 
@@ -1,3 +1,3 @@
1
1
  module MicroToken
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4".freeze
3
3
  end
@@ -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 = %q{A tiny random token generator}
12
- spec.summary = %q{A tiny random token generator}
13
- spec.homepage = "https://github.com/jamesotron/micro_token"
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[rake rspec].each do |dep|
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(8,format) }
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 be_true
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 be_true
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 be_true
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 be_true
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 be_true
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.3
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: 2013-06-23 00:00:00.000000000 Z
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
- - .travis.yml
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/jamesotron/micro_token
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.0.3
107
+ rubygems_version: 2.5.1
93
108
  signing_key:
94
109
  specification_version: 4
95
110
  summary: A tiny random token generator