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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2feee63566bac287b2b37df241fe9f6d921815a25fa9d8ffda0ec2e51e79da88
4
- data.tar.gz: '06879a851089f031f9729d7b9651e32ce5340ab2096db896c9001547b26be866'
3
+ metadata.gz: 789c1469292aaeac0682a128fa3edcb9a4e2adcb792c94acef5c41fa20a56160
4
+ data.tar.gz: 9fe04f567ebd19658ea950585fadccf98a42f0414a2d35451b23d7245f301287
5
5
  SHA512:
6
- metadata.gz: 592b580707bcb87cee3c82405b838011524d4197573f7ba3982c7b8cd3982fbd9605123e5b24a05f1c0b11be1bd54083fba0eaec27c47c157c361fb808ff1b90
7
- data.tar.gz: c4b47726fd86694bd4213e72749841ba398dd408ed2d239fb749108df89ad93b4601a02eca1eac765b1eb0e17e16d79b9e69146ac552fecde9f237f89f667043
6
+ metadata.gz: 26d3176ede91d962cf2a3debfcbf967c50e20cff478ea67176d6ea4f60ebbdf2a086c4941b823a49717fbf724d342d725291a92979bcd35bf987db21845d80ce
7
+ data.tar.gz: f55e66e2fb2a868e28c6b2bf209a39d13a6cb68635c5af308623e3f0939442b3df9c85e581e5c3667e932e8de056271b0d820907fecb657c2c8ccee654252242
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.8
4
3
  - 2.4.5
5
4
  - 2.5.3
6
5
  - 2.6.5
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.find_param(param)
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.find_param(param[:id])
151
+ @user = User.find_puid(param[:id])
128
152
  # ...
129
153
  end
130
154
  # ...
@@ -27,7 +27,7 @@ module PublicUid
27
27
  private
28
28
 
29
29
  def similar_uid_exist?
30
- @klass.where(@column => new_uid).count > 0
30
+ @klass.where(@column => new_uid).exists?
31
31
  end
32
32
 
33
33
  def check_column_existance
@@ -1,3 +1,3 @@
1
1
  module PublicUid
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
  end
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.0
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-03-22 00:00:00.000000000 Z
11
+ date: 2020-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord