uniqable 0.2.0 → 0.3.0
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 +5 -1
- data/Gemfile.lock +2 -2
- data/README.md +5 -1
- data/lib/uniqable.rb +12 -3
- data/lib/uniqable/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4114db480c0e9252f47842d2b146924b7e5e1f83
|
4
|
+
data.tar.gz: 0b4f10b5940dfcb66d7c636cce0b5dd0a7fa7f20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 261020540cb88c7799eca3add448c1628245e4f02af17c7f5516cdf58224cf57574111f334db84b767ecdb9be36780df99f8587253f48acaf6b32fd153ef3ca9
|
7
|
+
data.tar.gz: b35eb3bdbb3bfa4f2b66ec45775ee46cb7be44fd736ccb2ba957e7ff8d85bfbc5e96533a8173d171c42628bd1514ad4280e54a640aa97d86fe897a8d588a3eea
|
data/.circleci/config.yml
CHANGED
@@ -7,7 +7,7 @@ jobs:
|
|
7
7
|
build:
|
8
8
|
docker:
|
9
9
|
# specify the version you desire here
|
10
|
-
- image: circleci/ruby:2.
|
10
|
+
- image: circleci/ruby:2.3-node-browsers
|
11
11
|
|
12
12
|
# Specify service dependencies here if necessary
|
13
13
|
# CircleCI maintains a library of pre-built images
|
@@ -18,6 +18,10 @@ jobs:
|
|
18
18
|
|
19
19
|
steps:
|
20
20
|
- checkout
|
21
|
+
- run:
|
22
|
+
name: install sqlite
|
23
|
+
command: |
|
24
|
+
sudo apt-get install sqlite3
|
21
25
|
|
22
26
|
# Download and cache dependencies
|
23
27
|
- restore_cache:
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -42,7 +42,11 @@ anyway you have one more method `.find_uniqable` which one you can use to find y
|
|
42
42
|
```ruby
|
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]
|
46
50
|
```
|
47
51
|
and another one is `.uniqable_fields`
|
48
52
|
```ruby
|
data/lib/uniqable.rb
CHANGED
@@ -32,7 +32,9 @@ module Uniqable
|
|
32
32
|
|
33
33
|
# @return [self]
|
34
34
|
def where_uniqable(uid)
|
35
|
-
where_sql =
|
35
|
+
where_sql = key_uid?(uid) ?
|
36
|
+
uniqable_fields.map { |r| "#{table_name}.#{r} = :uid" }.join(' OR ') :
|
37
|
+
"#{self.primary_key} = :uid"
|
36
38
|
where(where_sql, uid: uid)
|
37
39
|
end
|
38
40
|
|
@@ -51,14 +53,21 @@ module Uniqable
|
|
51
53
|
def find_uniqable!(uid)
|
52
54
|
where_uniqable(uid).take!
|
53
55
|
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def key_uid?(uid)
|
60
|
+
uid.to_s =~ /\D+/
|
61
|
+
end
|
54
62
|
end
|
55
63
|
|
56
64
|
# Generate and set random and uniq field
|
57
65
|
# @TODO: split into 2 actions generate and set
|
58
66
|
def uniqable_uid(field)
|
59
67
|
loop do
|
60
|
-
|
61
|
-
|
68
|
+
uniq_code = SecureRandom.hex(8)
|
69
|
+
send("#{field}=", uniq_code)
|
70
|
+
break unless self.class.where(field => uniq_code).exists?
|
62
71
|
end
|
63
72
|
end
|
64
73
|
end
|
data/lib/uniqable/version.rb
CHANGED
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renat "MpaK" Ibragimov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|
154
154
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.6.
|
155
|
+
rubygems_version: 2.6.11
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: Uniqable - uniq and random token for ActiveRecord models
|