uniqable 0.3.1 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +1 -1
- data/.rakeTasks +7 -0
- data/.rubocop.yml +18 -1
- data/.ruby-version +1 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +53 -50
- data/README.md +1 -5
- data/Rakefile +1 -0
- data/lib/uniqable.rb +9 -5
- data/lib/uniqable/version.rb +1 -1
- data/uniqable.gemspec +6 -7
- metadata +25 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7edbf8a971d79a67b238754e0f0b05c32b93a71042a3b7dfa56a7b0893b74328
|
4
|
+
data.tar.gz: 54525e00eed37d7238c3638c07b58a1a93b9fdf92b02d8166c0959e05ddf956a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 564996a410171fcefa1219db14a0eb9908df7ac0f436b2902bf2bb1e80494c816ca44c8605ea8668c849994b86b2a81f187b460ba331339159dbf0f71a7e050d
|
7
|
+
data.tar.gz: 15c687084a4da77585af395dec754330b6404afa93017137ab0696e324982a637698a5d014e676e19685d26a9941e9c68615a767d631eb57135e6dfda836c8c6
|
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
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,82 +1,85 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
uniqable (0.
|
4
|
+
uniqable (0.4)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activemodel (
|
10
|
-
activesupport (=
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
i18n (
|
18
|
-
json (~> 1.7, >= 1.7.7)
|
9
|
+
activemodel (5.2.4.3)
|
10
|
+
activesupport (= 5.2.4.3)
|
11
|
+
activerecord (5.2.4.3)
|
12
|
+
activemodel (= 5.2.4.3)
|
13
|
+
activesupport (= 5.2.4.3)
|
14
|
+
arel (>= 9.0)
|
15
|
+
activesupport (5.2.4.3)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 0.7, < 2)
|
19
18
|
minitest (~> 5.1)
|
20
|
-
thread_safe (~> 0.1)
|
21
19
|
tzinfo (~> 1.1)
|
22
|
-
arel (
|
23
|
-
ast (2.4.
|
20
|
+
arel (9.0.0)
|
21
|
+
ast (2.4.1)
|
24
22
|
awesome_print (1.8.0)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
i18n (0.9.5)
|
23
|
+
concurrent-ruby (1.1.6)
|
24
|
+
diff-lcs (1.4.2)
|
25
|
+
i18n (1.8.3)
|
29
26
|
concurrent-ruby (~> 1.0)
|
30
|
-
|
31
|
-
|
32
|
-
parallel (1.
|
33
|
-
parser (2.
|
34
|
-
ast (~> 2.4.
|
35
|
-
powerpack (0.1.1)
|
27
|
+
minitest (5.14.1)
|
28
|
+
nanoid (2.0.0)
|
29
|
+
parallel (1.19.2)
|
30
|
+
parser (2.7.1.4)
|
31
|
+
ast (~> 2.4.1)
|
36
32
|
rainbow (3.0.0)
|
37
|
-
rake (
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
rspec-
|
42
|
-
|
43
|
-
rspec-
|
44
|
-
rspec-
|
33
|
+
rake (13.0.1)
|
34
|
+
regexp_parser (1.7.1)
|
35
|
+
rexml (3.2.4)
|
36
|
+
rspec (3.9.0)
|
37
|
+
rspec-core (~> 3.9.0)
|
38
|
+
rspec-expectations (~> 3.9.0)
|
39
|
+
rspec-mocks (~> 3.9.0)
|
40
|
+
rspec-core (3.9.2)
|
41
|
+
rspec-support (~> 3.9.3)
|
42
|
+
rspec-expectations (3.9.2)
|
45
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.
|
47
|
-
rspec-mocks (3.
|
44
|
+
rspec-support (~> 3.9.0)
|
45
|
+
rspec-mocks (3.9.1)
|
48
46
|
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
-
rspec-support (~> 3.
|
50
|
-
rspec-support (3.
|
47
|
+
rspec-support (~> 3.9.0)
|
48
|
+
rspec-support (3.9.3)
|
51
49
|
rspec_junit_formatter (0.4.1)
|
52
50
|
rspec-core (>= 2, < 4, != 2.12.0)
|
53
|
-
rubocop (0.
|
51
|
+
rubocop (0.86.0)
|
54
52
|
parallel (~> 1.10)
|
55
|
-
parser (>= 2.
|
56
|
-
powerpack (~> 0.1)
|
53
|
+
parser (>= 2.7.0.1)
|
57
54
|
rainbow (>= 2.2.2, < 4.0)
|
55
|
+
regexp_parser (>= 1.7)
|
56
|
+
rexml
|
57
|
+
rubocop-ast (>= 0.0.3, < 1.0)
|
58
58
|
ruby-progressbar (~> 1.7)
|
59
|
-
unicode-display_width (
|
60
|
-
|
59
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
60
|
+
rubocop-ast (0.0.3)
|
61
|
+
parser (>= 2.7.0.1)
|
62
|
+
ruby-progressbar (1.10.1)
|
61
63
|
sqlite3 (1.3.13)
|
62
64
|
thread_safe (0.3.6)
|
63
|
-
tzinfo (1.2.
|
65
|
+
tzinfo (1.2.7)
|
64
66
|
thread_safe (~> 0.1)
|
65
|
-
unicode-display_width (1.
|
67
|
+
unicode-display_width (1.7.0)
|
66
68
|
|
67
69
|
PLATFORMS
|
68
70
|
ruby
|
69
71
|
|
70
72
|
DEPENDENCIES
|
71
|
-
activerecord (~>
|
72
|
-
awesome_print
|
73
|
+
activerecord (~> 5.0)
|
74
|
+
awesome_print (~> 1.8.0)
|
73
75
|
bundler (~> 1.16)
|
74
|
-
|
75
|
-
|
76
|
+
nanoid
|
77
|
+
rake (>= 13.0.1)
|
78
|
+
rspec (~> 3.9)
|
76
79
|
rspec_junit_formatter
|
77
|
-
rubocop (~> 0.
|
78
|
-
sqlite3
|
80
|
+
rubocop (~> 0.82)
|
81
|
+
sqlite3 (~> 1.3.13)
|
79
82
|
uniqable!
|
80
83
|
|
81
84
|
BUNDLED WITH
|
82
|
-
1.
|
85
|
+
1.17.3
|
data/README.md
CHANGED
@@ -43,10 +43,6 @@ anyway you have one more method `.find_uniqable` which one you can use to find y
|
|
43
43
|
MyModel.find_uniqable params[:uid]
|
44
44
|
# or
|
45
45
|
MyModel.find_uniqable! params[:uid] # this will raise exception ActiveRecord::RecordNotFound if record is absent
|
46
|
-
# or you can use numerical ID same time and Uniqable will detect it and tries to find by primary key (as regular id)
|
47
|
-
MyModel.find_uniqable params[:id]
|
48
|
-
# or
|
49
|
-
MyModel.find_uniqable! params[:id]
|
50
46
|
```
|
51
47
|
and another one is `.uniqable_fields`
|
52
48
|
```ruby
|
@@ -57,7 +53,7 @@ You can also create your own token callback method and set the field:
|
|
57
53
|
|
58
54
|
```ruby
|
59
55
|
class MyModel
|
60
|
-
|
56
|
+
#...
|
61
57
|
def uniqable_uid(field)
|
62
58
|
self[field] = 100_000 + rand(999_999)
|
63
59
|
end
|
data/Rakefile
CHANGED
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
|
@@ -24,6 +25,7 @@ module Uniqable
|
|
24
25
|
end
|
25
26
|
|
26
27
|
return if to_param.blank? # :to_param option
|
28
|
+
|
27
29
|
define_method :to_param do
|
28
30
|
public_send(to_param)
|
29
31
|
end
|
@@ -34,7 +36,7 @@ module Uniqable
|
|
34
36
|
def where_uniqable(uid)
|
35
37
|
where_sql = key_uid?(uid) ?
|
36
38
|
uniqable_fields.map { |r| "#{table_name}.#{r} = :uid" }.join(' OR ') :
|
37
|
-
"#{table_name}.#{
|
39
|
+
"#{table_name}.#{primary_key} = :uid"
|
38
40
|
where(where_sql, uid: uid)
|
39
41
|
end
|
40
42
|
|
@@ -57,7 +59,7 @@ module Uniqable
|
|
57
59
|
private
|
58
60
|
|
59
61
|
def key_uid?(uid)
|
60
|
-
uid.to_s =~ /\D+/
|
62
|
+
uid.to_s =~ /\D+/ || uid.to_s.length >= 16
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
@@ -65,9 +67,11 @@ module Uniqable
|
|
65
67
|
# @TODO: split into 2 actions generate and set
|
66
68
|
def uniqable_uid(field)
|
67
69
|
loop do
|
68
|
-
uniq_code =
|
69
|
-
|
70
|
-
|
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
|
71
75
|
end
|
72
76
|
end
|
73
77
|
end
|
data/lib/uniqable/version.rb
CHANGED
data/uniqable.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
lib = File.expand_path('lib', __dir__)
|
@@ -22,11 +21,11 @@ Gem::Specification.new do |spec|
|
|
22
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
22
|
spec.require_paths = ['lib']
|
24
23
|
|
25
|
-
spec.add_development_dependency 'activerecord', '~>
|
26
|
-
spec.add_development_dependency 'awesome_print'
|
24
|
+
spec.add_development_dependency 'activerecord', '~> 5.0'
|
25
|
+
spec.add_development_dependency 'awesome_print', '~> 1.8.0'
|
27
26
|
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.
|
31
|
-
spec.add_development_dependency 'sqlite3'
|
27
|
+
spec.add_development_dependency 'rake', '>= 13.0.1'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
29
|
+
spec.add_development_dependency 'rubocop', '~> 0.82'
|
30
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3.13'
|
32
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uniqable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.4'
|
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-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '5.0'
|
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
|
-
version:
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: awesome_print
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.8.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: 1.8.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,58 +56,58 @@ dependencies:
|
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 13.0.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 13.0.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
75
|
+
version: '3.9'
|
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: '3.
|
82
|
+
version: '3.9'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
89
|
+
version: '0.82'
|
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: '0.
|
96
|
+
version: '0.82'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: sqlite3
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 1.3.13
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 1.3.13
|
111
111
|
description: Generate a unique, random token for ActiveRecord models.
|
112
112
|
email:
|
113
113
|
- mrak69@gmail.com
|
@@ -117,6 +117,7 @@ extra_rdoc_files: []
|
|
117
117
|
files:
|
118
118
|
- ".circleci/config.yml"
|
119
119
|
- ".gitignore"
|
120
|
+
- ".rakeTasks"
|
120
121
|
- ".rspec"
|
121
122
|
- ".rubocop.yml"
|
122
123
|
- ".ruby-gems"
|
@@ -136,7 +137,7 @@ files:
|
|
136
137
|
homepage: https://github.com/mpakus/uniqable
|
137
138
|
licenses: []
|
138
139
|
metadata: {}
|
139
|
-
post_install_message:
|
140
|
+
post_install_message:
|
140
141
|
rdoc_options: []
|
141
142
|
require_paths:
|
142
143
|
- lib
|
@@ -151,9 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
152
|
- !ruby/object:Gem::Version
|
152
153
|
version: '0'
|
153
154
|
requirements: []
|
154
|
-
|
155
|
-
|
156
|
-
signing_key:
|
155
|
+
rubygems_version: 3.0.8
|
156
|
+
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: Uniqable - uniq and random token for ActiveRecord models
|
159
159
|
test_files: []
|