public_uid 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/README.md +27 -3
- data/lib/public_uid/set_public_uid.rb +1 -1
- data/lib/public_uid/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 789c1469292aaeac0682a128fa3edcb9a4e2adcb792c94acef5c41fa20a56160
|
4
|
+
data.tar.gz: 9fe04f567ebd19658ea950585fadccf98a42f0414a2d35451b23d7245f301287
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26d3176ede91d962cf2a3debfcbf967c50e20cff478ea67176d6ea4f60ebbdf2a086c4941b823a49717fbf724d342d725291a92979bcd35bf987db21845d80ce
|
7
|
+
data.tar.gz: f55e66e2fb2a868e28c6b2bf209a39d13a6cb68635c5af308623e3f0939442b3df9c85e581e5c3667e932e8de056271b0d820907fecb657c2c8ccee654252242
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -64,7 +64,7 @@ end
|
|
64
64
|
|
65
65
|
### Step 2a - Using Rails concern
|
66
66
|
|
67
|
-
> a.k.a - the easy way for Rails
|
67
|
+
> a.k.a - the easy way for Rails (availible since version 2.1.0)
|
68
68
|
|
69
69
|
```ruby
|
70
70
|
class User < ActiveRecord::Base
|
@@ -72,6 +72,28 @@ class User < ActiveRecord::Base
|
|
72
72
|
end
|
73
73
|
```
|
74
74
|
|
75
|
+
Example:
|
76
|
+
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
user = User.create
|
80
|
+
user.public_uid
|
81
|
+
# => "xxxxxxxx"
|
82
|
+
|
83
|
+
user.to_param
|
84
|
+
# => "xxxxxxxx"
|
85
|
+
|
86
|
+
User.find_puid('xxxxxxxx')
|
87
|
+
# => <#User ...>
|
88
|
+
User.find_puid('not_existing')
|
89
|
+
# => nil
|
90
|
+
|
91
|
+
User.find_puid!('xxxxxxxx')
|
92
|
+
# => <#User ...>
|
93
|
+
User.find_puid!('not_existing')
|
94
|
+
# PublicUid::RecordNotFound (User 'not_existing' not found)
|
95
|
+
```
|
96
|
+
|
75
97
|
This will automatically:
|
76
98
|
|
77
99
|
* assumes your model has `public_uid` column and generate public_uid value for you
|
@@ -85,6 +107,8 @@ If you need more customization please follow **Step 2b** instead
|
|
85
107
|
|
86
108
|
### Step 2b - Using manual generate method
|
87
109
|
|
110
|
+
> a.k.a bit harder than `2.a` but more flexible way for Rails
|
111
|
+
|
88
112
|
Tell your model to generate the public identifier
|
89
113
|
|
90
114
|
```ruby
|
@@ -111,7 +135,7 @@ Then you can do more clever things like having urls based on `public_uid` and `t
|
|
111
135
|
class User < ActiveRecord::Base
|
112
136
|
generate_public_uid
|
113
137
|
|
114
|
-
def self.
|
138
|
+
def self.find_puid(param)
|
115
139
|
find_by! public_uid: param.split('-').first
|
116
140
|
end
|
117
141
|
|
@@ -124,7 +148,7 @@ end
|
|
124
148
|
class UsersController < ActionController::Base
|
125
149
|
# ...
|
126
150
|
def show
|
127
|
-
@user = User.
|
151
|
+
@user = User.find_puid(param[:id])
|
128
152
|
# ...
|
129
153
|
end
|
130
154
|
# ...
|
data/lib/public_uid/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: public_uid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Valent
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|