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 +4 -4
- data/.circleci/config.yml +1 -1
- data/.rakeTasks +7 -0
- data/.rubocop.yml +18 -1
- data/.ruby-version +1 -1
- data/Gemfile.lock +51 -48
- data/lib/uniqable.rb +16 -7
- data/lib/uniqable/version.rb +1 -1
- data/uniqable.gemspec +8 -6
- metadata +39 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 380e4507b0e28fda9883c3b9308d849e5f79b14499116318c6f53d91e3858e1f
|
4
|
+
data.tar.gz: bc71daee409bc388694fca896ad5f93de3c0ee5f96dd39b5691e28c42c9da6a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67cb4c95fb2be012c5435b7244bc7903d74763e53f47d4b1b137a47470fe5531be89fa156c2c28a6249561453dd86483873370be304f938827ec9c3eaf979565
|
7
|
+
data.tar.gz: c630d62afa874d11c0a2b4b0e774266561b0aaf3fe7a01de46f72c1766f46a53abd03b0864e5369731308fedb189aef89942dbca4b11053f0f03788828f696e2
|
data/.circleci/config.yml
CHANGED
data/.rakeTasks
ADDED
@@ -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>
|
data/.rubocop.yml
CHANGED
@@ -3,4 +3,21 @@ Metrics/LineLength:
|
|
3
3
|
Metrics/BlockLength:
|
4
4
|
ExcludedMethods: ['describe', 'context']
|
5
5
|
AllCops:
|
6
|
-
TargetRubyVersion: 2.
|
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
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.4
|
data/Gemfile.lock
CHANGED
@@ -1,81 +1,84 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
uniqable (0.
|
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 (
|
10
|
-
activesupport (=
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
i18n (
|
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 (
|
23
|
-
ast (2.4.
|
21
|
+
arel (9.0.0)
|
22
|
+
ast (2.4.1)
|
24
23
|
awesome_print (1.8.0)
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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 (
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
rspec-
|
42
|
-
|
43
|
-
rspec-
|
44
|
-
rspec-
|
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.
|
47
|
-
rspec-mocks (3.
|
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.
|
50
|
-
rspec-support (3.
|
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.
|
54
|
-
jaro_winkler (~> 1.5.1)
|
52
|
+
rubocop (0.86.0)
|
55
53
|
parallel (~> 1.10)
|
56
|
-
parser (>= 2.
|
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, <
|
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.
|
66
|
+
tzinfo (1.2.7)
|
64
67
|
thread_safe (~> 0.1)
|
65
|
-
unicode-display_width (1.
|
68
|
+
unicode-display_width (1.7.0)
|
66
69
|
|
67
70
|
PLATFORMS
|
68
71
|
ruby
|
69
72
|
|
70
73
|
DEPENDENCIES
|
71
|
-
activerecord (~>
|
72
|
-
awesome_print
|
74
|
+
activerecord (~> 5.0)
|
75
|
+
awesome_print (~> 1.8.0)
|
73
76
|
bundler (~> 1.16)
|
74
|
-
rake (
|
75
|
-
rspec (~> 3.
|
77
|
+
rake (>= 13.0.1)
|
78
|
+
rspec (~> 3.9)
|
76
79
|
rspec_junit_formatter
|
77
|
-
rubocop (~> 0.
|
78
|
-
sqlite3 (~> 1.3.
|
80
|
+
rubocop (~> 0.82)
|
81
|
+
sqlite3 (~> 1.3.13)
|
79
82
|
uniqable!
|
80
83
|
|
81
84
|
BUNDLED WITH
|
data/lib/uniqable.rb
CHANGED
@@ -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
|
-
|
37
|
-
|
38
|
-
|
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 =
|
64
|
-
|
65
|
-
|
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
|
data/lib/uniqable/version.rb
CHANGED
data/uniqable.gemspec
CHANGED
@@ -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.
|
25
|
-
|
26
|
-
spec.add_development_dependency '
|
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', '
|
29
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
30
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
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.
|
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:
|
11
|
+
date: 2020-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: nanoid
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
type: :
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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.
|
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.
|
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.
|
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:
|
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.
|
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: []
|