uniqable 0.3.2 → 0.4.1

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
  SHA256:
3
- metadata.gz: b28ea2e4128fd506d1983847dfde61915acf8550c417fbc5eaba75e11da56986
4
- data.tar.gz: 39ef933406d49dcf040aabf68f2c5469c317d52630dd4f65a52b4a40a993bb97
3
+ metadata.gz: 380e4507b0e28fda9883c3b9308d849e5f79b14499116318c6f53d91e3858e1f
4
+ data.tar.gz: bc71daee409bc388694fca896ad5f93de3c0ee5f96dd39b5691e28c42c9da6a9
5
5
  SHA512:
6
- metadata.gz: 45d7d098218f0071b1373e23c824f119f0c9b03cf5ee097fb668e34653a11328b9d0684c519a6eaeaa9e450d265f34fa3fc4e7035c4989186b00faef987b088e
7
- data.tar.gz: 37802f6ce7ba3f591559a271d597111ca13743b43345b8b37e986426e2360a9e089b032de476567ed444a924864aca22dba1e339b9fb04603b7e48dcf2fac3d2
6
+ metadata.gz: 67cb4c95fb2be012c5435b7244bc7903d74763e53f47d4b1b137a47470fe5531be89fa156c2c28a6249561453dd86483873370be304f938827ec9c3eaf979565
7
+ data.tar.gz: c630d62afa874d11c0a2b4b0e774266561b0aaf3fe7a01de46f72c1766f46a53abd03b0864e5369731308fedb189aef89942dbca4b11053f0f03788828f696e2
@@ -7,7 +7,7 @@ jobs:
7
7
  build:
8
8
  docker:
9
9
  # specify the version you desire here
10
- - image: circleci/ruby:2.3-node-browsers
10
+ - image: circleci/ruby:2.4-node-browsers
11
11
 
12
12
  # Specify service dependencies here if necessary
13
13
  # CircleCI maintains a library of pre-built images
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
@@ -3,4 +3,21 @@ Metrics/LineLength:
3
3
  Metrics/BlockLength:
4
4
  ExcludedMethods: ['describe', 'context']
5
5
  AllCops:
6
- TargetRubyVersion: 2.3
6
+ TargetRubyVersion: 2.4
7
+
8
+ Layout/SpaceAroundMethodCallOperator:
9
+ Enabled: true
10
+ Lint/RaiseException:
11
+ Enabled: true
12
+ Lint/StructNewOverride:
13
+ Enabled: true
14
+ Style/ExponentialNotation:
15
+ Enabled: true
16
+ Style/HashEachMethods:
17
+ Enabled: true
18
+ Style/HashTransformKeys:
19
+ Enabled: true
20
+ Style/HashTransformValues:
21
+ Enabled: true
22
+ Style/MultilineTernaryOperator:
23
+ Enabled: false
@@ -1 +1 @@
1
- 2.3.3
1
+ 2.4.4
@@ -1,81 +1,84 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- uniqable (0.3.2)
4
+ uniqable (0.4.1)
5
+ nanoid (~> 2.0)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
- activemodel (4.1.14.2)
10
- activesupport (= 4.1.14.2)
11
- builder (~> 3.1)
12
- activerecord (4.1.14.2)
13
- activemodel (= 4.1.14.2)
14
- activesupport (= 4.1.14.2)
15
- arel (~> 5.0.0)
16
- activesupport (4.1.14.2)
17
- i18n (~> 0.6, >= 0.6.9)
18
- json (~> 1.7, >= 1.7.7)
10
+ activemodel (5.2.4.3)
11
+ activesupport (= 5.2.4.3)
12
+ activerecord (5.2.4.3)
13
+ activemodel (= 5.2.4.3)
14
+ activesupport (= 5.2.4.3)
15
+ arel (>= 9.0)
16
+ activesupport (5.2.4.3)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
19
  minitest (~> 5.1)
20
- thread_safe (~> 0.1)
21
20
  tzinfo (~> 1.1)
22
- arel (5.0.1.20140414130214)
23
- ast (2.4.0)
21
+ arel (9.0.0)
22
+ ast (2.4.1)
24
23
  awesome_print (1.8.0)
25
- builder (3.2.3)
26
- concurrent-ruby (1.1.5)
27
- diff-lcs (1.3)
28
- i18n (0.9.5)
24
+ concurrent-ruby (1.1.6)
25
+ diff-lcs (1.4.2)
26
+ i18n (1.8.3)
29
27
  concurrent-ruby (~> 1.0)
30
- jaro_winkler (1.5.3)
31
- json (1.8.6)
32
- minitest (5.11.3)
33
- parallel (1.17.0)
34
- parser (2.6.3.0)
35
- ast (~> 2.4.0)
28
+ minitest (5.14.1)
29
+ nanoid (2.0.0)
30
+ parallel (1.19.2)
31
+ parser (2.7.1.4)
32
+ ast (~> 2.4.1)
36
33
  rainbow (3.0.0)
37
- rake (10.5.0)
38
- rspec (3.8.0)
39
- rspec-core (~> 3.8.0)
40
- rspec-expectations (~> 3.8.0)
41
- rspec-mocks (~> 3.8.0)
42
- rspec-core (3.8.1)
43
- rspec-support (~> 3.8.0)
44
- rspec-expectations (3.8.4)
34
+ rake (13.0.1)
35
+ regexp_parser (1.7.1)
36
+ rexml (3.2.4)
37
+ rspec (3.9.0)
38
+ rspec-core (~> 3.9.0)
39
+ rspec-expectations (~> 3.9.0)
40
+ rspec-mocks (~> 3.9.0)
41
+ rspec-core (3.9.2)
42
+ rspec-support (~> 3.9.3)
43
+ rspec-expectations (3.9.2)
45
44
  diff-lcs (>= 1.2.0, < 2.0)
46
- rspec-support (~> 3.8.0)
47
- rspec-mocks (3.8.1)
45
+ rspec-support (~> 3.9.0)
46
+ rspec-mocks (3.9.1)
48
47
  diff-lcs (>= 1.2.0, < 2.0)
49
- rspec-support (~> 3.8.0)
50
- rspec-support (3.8.2)
48
+ rspec-support (~> 3.9.0)
49
+ rspec-support (3.9.3)
51
50
  rspec_junit_formatter (0.4.1)
52
51
  rspec-core (>= 2, < 4, != 2.12.0)
53
- rubocop (0.71.0)
54
- jaro_winkler (~> 1.5.1)
52
+ rubocop (0.86.0)
55
53
  parallel (~> 1.10)
56
- parser (>= 2.6)
54
+ parser (>= 2.7.0.1)
57
55
  rainbow (>= 2.2.2, < 4.0)
56
+ regexp_parser (>= 1.7)
57
+ rexml
58
+ rubocop-ast (>= 0.0.3, < 1.0)
58
59
  ruby-progressbar (~> 1.7)
59
- unicode-display_width (>= 1.4.0, < 1.7)
60
+ unicode-display_width (>= 1.4.0, < 2.0)
61
+ rubocop-ast (0.0.3)
62
+ parser (>= 2.7.0.1)
60
63
  ruby-progressbar (1.10.1)
61
64
  sqlite3 (1.3.13)
62
65
  thread_safe (0.3.6)
63
- tzinfo (1.2.5)
66
+ tzinfo (1.2.7)
64
67
  thread_safe (~> 0.1)
65
- unicode-display_width (1.6.0)
68
+ unicode-display_width (1.7.0)
66
69
 
67
70
  PLATFORMS
68
71
  ruby
69
72
 
70
73
  DEPENDENCIES
71
- activerecord (~> 4.1.14.1)
72
- awesome_print
74
+ activerecord (~> 5.0)
75
+ awesome_print (~> 1.8.0)
73
76
  bundler (~> 1.16)
74
- rake (~> 10.0)
75
- rspec (~> 3.0)
77
+ rake (>= 13.0.1)
78
+ rspec (~> 3.9)
76
79
  rspec_junit_formatter
77
- rubocop (~> 0.49)
78
- sqlite3 (~> 1.3.6)
80
+ rubocop (~> 0.82)
81
+ sqlite3 (~> 1.3.13)
79
82
  uniqable!
80
83
 
81
84
  BUNDLED WITH
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'uniqable/version'
4
+ require 'nanoid'
4
5
 
5
6
  # Generates uniq, random token for ActiveRecord model's fields
6
7
  module Uniqable
@@ -33,10 +34,10 @@ module Uniqable
33
34
 
34
35
  # @return [self]
35
36
  def where_uniqable(uid)
36
- where(
37
- uniqable_fields.map { |r| "#{table_name}.#{r} = :uid" }.join(' OR '),
38
- uid: uid
39
- )
37
+ where_sql = key_uid?(uid) ?
38
+ uniqable_fields.map { |r| "#{table_name}.#{r} = :uid" }.join(' OR ') :
39
+ "#{table_name}.#{primary_key} = :uid"
40
+ where(where_sql, uid: uid)
40
41
  end
41
42
 
42
43
  # Find record by one of the uniq field
@@ -54,15 +55,23 @@ module Uniqable
54
55
  def find_uniqable!(uid)
55
56
  where_uniqable(uid).take!
56
57
  end
58
+
59
+ private
60
+
61
+ def key_uid?(uid)
62
+ uid.to_s =~ /\D+/ || uid.to_s.length >= 16
63
+ end
57
64
  end
58
65
 
59
66
  # Generate and set random and uniq field
60
67
  # @TODO: split into 2 actions generate and set
61
68
  def uniqable_uid(field)
62
69
  loop do
63
- uniq_code = SecureRandom.hex(8)
64
- send("#{field}=", uniq_code)
65
- break unless self.class.where(field => uniq_code).exists?
70
+ uniq_code = Nanoid.generate(size: 16)
71
+ if uniq_code =~ /\D+/
72
+ send("#{field}=", uniq_code)
73
+ break unless self.class.where(field => uniq_code).exists?
74
+ end
66
75
  end
67
76
  end
68
77
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uniqable
4
- VERSION = '0.3.2'
4
+ VERSION = '0.4.1'
5
5
  end
@@ -21,11 +21,13 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ['lib']
23
23
 
24
- spec.add_development_dependency 'sqlite3', '~> 1.3.6'
25
- spec.add_development_dependency 'activerecord', '~> 4.1.14.1'
26
- spec.add_development_dependency 'awesome_print'
24
+ spec.add_dependency 'nanoid', '~> 2.0'
25
+
26
+ spec.add_development_dependency 'activerecord', '~> 5.0'
27
+ spec.add_development_dependency 'awesome_print', '~> 1.8.0'
27
28
  spec.add_development_dependency 'bundler', '~> 1.16'
28
- spec.add_development_dependency 'rake', '~> 10.0'
29
- spec.add_development_dependency 'rspec', '~> 3.0'
30
- spec.add_development_dependency 'rubocop', '~> 0.49'
29
+ spec.add_development_dependency 'rake', '>= 13.0.1'
30
+ spec.add_development_dependency 'rspec', '~> 3.9'
31
+ spec.add_development_dependency 'rubocop', '~> 0.82'
32
+ spec.add_development_dependency 'sqlite3', '~> 1.3.13'
31
33
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uniqable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renat "MpaK" Ibragimov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-18 00:00:00.000000000 Z
11
+ date: 2020-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: sqlite3
14
+ name: nanoid
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.6
20
- type: :development
19
+ version: '2.0'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3.6
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 4.1.14.1
33
+ version: '5.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
- version: 4.1.14.1
40
+ version: '5.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: awesome_print
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.8.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.8.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -70,44 +70,58 @@ dependencies:
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: 13.0.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: 13.0.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '3.0'
89
+ version: '3.9'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '3.0'
96
+ version: '3.9'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.49'
103
+ version: '0.82'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.82'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.3.13
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0.49'
124
+ version: 1.3.13
111
125
  description: Generate a unique, random token for ActiveRecord models.
112
126
  email:
113
127
  - mrak69@gmail.com
@@ -117,6 +131,7 @@ extra_rdoc_files: []
117
131
  files:
118
132
  - ".circleci/config.yml"
119
133
  - ".gitignore"
134
+ - ".rakeTasks"
120
135
  - ".rspec"
121
136
  - ".rubocop.yml"
122
137
  - ".ruby-gems"
@@ -136,7 +151,7 @@ files:
136
151
  homepage: https://github.com/mpakus/uniqable
137
152
  licenses: []
138
153
  metadata: {}
139
- post_install_message:
154
+ post_install_message:
140
155
  rdoc_options: []
141
156
  require_paths:
142
157
  - lib
@@ -151,8 +166,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
166
  - !ruby/object:Gem::Version
152
167
  version: '0'
153
168
  requirements: []
154
- rubygems_version: 3.0.4
155
- signing_key:
169
+ rubygems_version: 3.0.8
170
+ signing_key:
156
171
  specification_version: 4
157
172
  summary: Uniqable - uniq and random token for ActiveRecord models
158
173
  test_files: []